<hi****@gmail.com> wrote in message
news:11**********************@z14g2000cwz.googlegr oups.com...
How to get the header values in the sql with union.
For example,
select deptno as dep,deptname as dname,location as loc,mgrno as mgr
from dept
union
select empno,empname,'Employee','' from emp
I need output with
header:
dep dname loc mgr
1 mkt 4 34
2 sls 4 33
34 James Employee 45
Thank for your time.
I was surprised that your query didn't work just the way it was so I tried
it and confirmed that it failed to put the desired headings at the top of
the columns in DB2 for Windows/Unix/Linux, Version 8 (Fixpack 8). (By the
way, I had to change to table names from 'emp' and 'dept' to 'employee' and
'department' so I assume you are on an older version of DB2 or on a
different operating system.)
I got the desired headings to appear by putting the 'as' expressions in
_both_ queries:
select deptno as dep,deptname as dname,location as loc,mgrno as mgr
from department
union
select empno as dep,lastname as dname,'Employee' as loc,'' as mgr from
employee
Rhino