Icon View Incident Report

Minor Minor
Reported By: Hendrik Grutzmacher
Reported On: 2/8/2013
For: Version 2.11 Build 3
# 3743 Ambiguous ORDER BY Clause Can Cause Odd Results with UNIONed Queries

I have a strange issue that an ORDER BY after a UNION ALL duplicates the row from the second resultset.

The following SQL gives 6 records - normally it should be 4 (3 from the first part and 1 from the second). the second gives now 3 rows (exactly the same).

SELECT ORDER, T1.NAME FROM T_CUSTOMFIELDS T1 WHERE TABLE_NAME='t_offers'
union all
SELECT coalesce(max(order), 0) + 1, '<neu>' from t_customfields where table_name='t_offers'
order by "order"



Comments Comments and Workarounds
The issue is that the query is ambiguous. What happens is this:

When EDB goes to run the query, it sees that the ORDER BY is on the column "order". This is fine for the first query, which actually selects a column called "order". However, for the second query, EDB sees that the "order" column is not being selected and then adds it (hidden) to the list of SELECT expressions. This act is what causes the ambiguity. EDB no longer will treat the second query as a single-row result because it's now selecting from a non-aggregated column, and what results is an invalid query (due to the MAX() call). This now causes a compilation error, as it should.

Adding an "Order" correlation name for first expression in the second query will fix this.


Resolution Resolution
Fixed Problem on 2/9/2013 in version 2.12 build 1


Products Affected Products Affected
ElevateDB Additional Software and Utilities
ElevateDB DAC Client-Server
ElevateDB DAC Client-Server with Source
ElevateDB DAC Standard
ElevateDB DAC Standard with Source
ElevateDB DAC Trial
ElevateDB LCL Standard with Source
ElevateDB PHP Standard
ElevateDB PHP Standard with Source
ElevateDB PHP Trial
ElevateDB VCL Client-Server
ElevateDB VCL Client-Server with Source
ElevateDB VCL Standard
ElevateDB VCL Standard with Source
ElevateDB VCL Trial

Image