cjkenworthy
Programmer
I'm trying to return a list of distinct attributes, and a COUNT of the number of rows with that distinct attributes, this is from 2 tables with the same schema:
Results e.g.
(PackReference, Total)
ABC123 2
DEF678 1
GHI901 6
SELECT PackReference, SUM('TotalRecords') AS 'Total' FROM
(
SELECT PackReference, COUNT(*) AS 'TotalRecords' FROM table1 GROUP BY PackReference
UNION ALL
SELECT PackReference, COUNT(*) AS 'TotalRecords' FROM table2 GROUP BY PackReference
ORDER BY PackReference
)
AS Results
GROUP BY PackReference
However, the query does return a list of distinct PackReferences, but the total is 0 for each record.
I have looked at other postings on UNION and COUNT, but they only seem to concentrate on the COUNT, and not the fact that there is also a GROUP BY to include the first attribute.
Any help would be greatly appreciated.
Chris.
Results e.g.
(PackReference, Total)
ABC123 2
DEF678 1
GHI901 6
SELECT PackReference, SUM('TotalRecords') AS 'Total' FROM
(
SELECT PackReference, COUNT(*) AS 'TotalRecords' FROM table1 GROUP BY PackReference
UNION ALL
SELECT PackReference, COUNT(*) AS 'TotalRecords' FROM table2 GROUP BY PackReference
ORDER BY PackReference
)
AS Results
GROUP BY PackReference
However, the query does return a list of distinct PackReferences, but the total is 0 for each record.
I have looked at other postings on UNION and COUNT, but they only seem to concentrate on the COUNT, and not the fact that there is also a GROUP BY to include the first attribute.
Any help would be greatly appreciated.
Chris.