Topic
1 reply Latest Post - ‏2013-01-05T08:27:16Z by SystemAdmin
SystemAdmin
SystemAdmin
3105 Posts
ACCEPTED ANSWER

Pinned topic The column name generated in UNION ALL

‏2012-11-21T14:25:52Z |
Dears,

Assuming we have a UNION ALL query from two sub queries with different column names just like:

SELECT colName1 FROM table1
UNION ALL
SELECT colName2 FROM table2

In other databases, this returns a result set whose column is colName1 which is the same as the column listed in the first subquery.

But in DB2ZOS, it seems the columns are numbers like 1,2,3,4.

The question is if I want to wrap the UNION ALL query into an outer SELECT statement, How should I list the new column names? Is there a configuration to make DB2ZOS consistent with others

Thanks,
RR
Updated on 2013-01-05T08:27:16Z at 2013-01-05T08:27:16Z by SystemAdmin
  • SystemAdmin
    SystemAdmin
    3105 Posts
    ACCEPTED ANSWER

    Re: The column name generated in UNION ALL

    ‏2013-01-05T08:27:16Z  in response to SystemAdmin
    you can just alias your columns anyway you want

    select colname1 as my_special_column from table1
    union all
    select colname2 from table2

    the result table should have a column named my_special_column