New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UNION works implizit with DISTINCT [CORE1917] #2350
Comments
Commented by: @hvlad UNION, by default and by SQL standard, removed duplicates. |
Modified by: Joe Blocher (joblo)description: the following sql-statement should return 2 rows, but actually returns only 1 --------------------------------------------- you can test immediatly - should return 2 rows too: => a simple union statement for example: The single statement "SELECT FieldX as Value FROM TABLE_A" returns 2 rows ------------------------------------------------ SELECT DISTINCT FieldX as Value FROM TABLE_A I think, this is not correct, in a more complex query it can be very dangerous. you can test it immediatly - not exactly the same, but in my opinion a bug too: compare to summary: UNION works implizit as GROUP BY => UNION works implizit with DISTINCT |
Commented by: @pmakowski It is conform to SQL standard |
Modified by: @pmakowskistatus: Resolved [ 5 ] => Closed [ 6 ] |
Submitted by: Joe Blocher (joblo)
a simple union statement
----------------------------------
SELECT FieldX as Value FROM TABLE_A
UNION
SELECT FieldY as Value FROM TABLE_B
for example:
-------------------------------
TABLE_A has 2 rows with the same value in FieldX
TABLE_B has 1 row with another value in FieldY
The single statement "SELECT FieldX as Value FROM TABLE_A" returns 2 rows
The single statement "SELECT FieldY as Value FROM TABLE_B" returns 1 row
But the above UNION statement only returns 2 rows??
------------------------------------------------
That means, it acts implizit like:
SELECT DISTINCT FieldX as Value FROM TABLE_A
UNION
SELECT DISTINCT FieldY as Value FROM TABLE_B
I think, this is not correct, in a more complex query it can be very dangerous.
you can test it immediatly - not exactly the same, but in my opinion a bug too:
------------------------------------------------
SELECT 1, RDB$RELATION_ID FROM RDB$DATABASE
UNION
SELECT 1, RDB$RELATION_ID FROM RDB$DATABASE
compare to
------------------------------------------------
SELECT 1, RDB$RELATION_ID FROM RDB$DATABASE
UNION
SELECT 2, RDB$RELATION_ID FROM RDB$DATABASE
The text was updated successfully, but these errors were encountered: