If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > DB2 Union Function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-09-11, 00:56
echarish echarish is offline
Registered User
 
Join Date: Sep 2011
Posts: 1
Red face DB2 Union Function

Hi
i am using below query

select Year(current_date) from SYSIBM.SYSDUMMY1
UNION
select Month(current_date) from SYSIBM.SYSDUMMY1
UNION
select day(current_date) from SYSIBM.SYSDUMMY1


to select year month and day, this query works fine if the month and day are not same i.e.
if the date is 2011-09-08 than it returns
2011
9
8

but if the date is 2011-09-09 it only returns two rows
2011
9

in both the cases if i run queries individually it returns proper values..

Can you please tell me whats going wrong with this....
Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 09-09-11, 01:46
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Use "UNION ALL" instead of "UNION".

UNION removes duplicated rows.
Reply With Quote
  #3 (permalink)  
Old 09-09-11, 02:40
przytula_guy przytula_guy is offline
Registered User
 
Join Date: Apr 2006
Location: Belgium
Posts: 1,159
teachers will have big opportunities..
DB2 University
__________________
Best Regards, Guy Przytula
Database Software Consultant
DB2 UDB LUW Certified V7-V8-V9-V9.7 DB Admin - Dprop..
Information Server Datastage Certified
http://www.infocura.be
Reply With Quote
Reply

Tags
db2, union

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On