# UNION query question

My query is:

``````SELECT BRAND,BRAND_GROUP, SUB_BRAND ,SUM(INCOME) AS TOTAL_INCOME FROM
"tema".MMT WHERE BRAND_GROUP IS NULL AND SUB_BRAND IS NULL GROUP BY
BRAND,BRAND_GROUP,SUB_BRAND

UNION
SELECT BRAND,BRAND_GROUP, SUB_BRAND ,SUM(INCOME) AS TOTAL_INCOME FROM
"tema".BGT WHERE BRAND_GROUP IS NULL AND SUB_BRAND IS NULL GROUP BY
BRAND,BRAND_GROUP,SUB_BRAND;
``````

and my output is :

``````BRAND BRAND_GROUP SUB_BRAND TOTAL_INCOME
----- ----------- --------- ------------
GBS   NULL        NULL             10000
SWG   NULL        NULL             10000
GBS   NULL        NULL             20000
STG   NULL        NULL             20000
GTS   NULL        NULL             30000
``````

The problem is that i have 2 categories of BRAND and I want to have just 1. Like this :

``````Brand       Brand_Group     Sub_brand       Total_Income
GBS                  -          -           30000
STG                  -          -           20000
GTS                  -          -           30000
SWG                  -          -           10000
``````

Can someone help me with an ideea?

Sum after you did the union (hope DB2 does it this way):

``````SELECT  BRAND, BRAND_GROUP, SUB_BRAND, SUM(INCOME) AS TOTAL_INCOME
FROM    (SELECT BRAND, BRAND_GROUP, SUB_BRAND, INCOME
FROM   "tema".MMT
WHERE  BRAND_GROUP IS NULL
AND    SUB_BRAND IS NULL
UNION ALL
SELECT BRAND, BRAND_GROUP, SUB_BRAND, INCOME
FROM   "tema".BGT
WHERE  BRAND_GROUP IS NULL
AND    SUB_BRAND IS NULL) AS T
GROUP BY BRAND, BRAND_GROUP, SUB_BRAND;
``````

Just a question. Why do you need the `BRAND_GROUP` and `SUB_BRAND` (since they are both NULL)?