the straighforward answer is... using a LEFT OUTER JOIN
the left table would be a table containing all the codes you want to display, and the right table would be your data
you don't actually have to have a permanent table for the codes (although it's probably a good idea)
Code:
SELECT codes.field1
, SUM(data.total) AS total
FROM ( SELECT 'ABC' AS field1
UNION ALL
SELECT 'DEF'
UNION ALL
SELECT 'GHI' ) AS codes
LEFT OUTER
JOIN ( /* your union query */ ) AS data
GROUP
BY codes.field1
if you do decide to store a premanent table for your codes, it might be worth it to store the list of translations for each code, so that your queries can avoid the ugly CASE expressions, too
Bookmarks