Subject Re: [firebird-support] Possible bug with GROUP BY and UNION
Author Arno Brinkman
Hi,

> Then execute the following query:
>
> SELECT SUM(AMOUNT)
> FROM TBL
> WHERE TYPE_OF_ROW = 0
> GROUP BY TYPE_OF_ROW
> UNION
> SELECT AMOUNT
> FROM TBL
> WHERE TYPE_OF_ROW <> 0
>
> The expected result is:
>
> 11.00
> 11.00
> 12.00
>
> Instead, the result is
>
> 11.00
> 12.00

That's the different between UNION and UNION ALL. Without ALL automaticly a
DISTINCT is performed on the resultset.

Use this query:

SELECT
SUM(AMOUNT)
FROM
TBL
WHERE
TYPE_OF_ROW = 0
GROUP BY
TYPE_OF_ROW
UNION ALL
SELECT
AMOUNT
FROM
TBL
WHERE
TYPE_OF_ROW <> 0

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/

Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep :
news://newsgroups.firebirdsql.info