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 > return one result set from 2 queries

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-05-09, 20:56
gamo gamo is offline
Registered User
 
Join Date: Jul 2009
Location: Sydney
Posts: 13
return one result set from 2 queries

Say I have 2 tables, but in this particular instance I am only interested in columns which are equivalent in both of them

for e.g.

table A

id | status | other column which I'm not interested in
______________________
a1 | good | whatever
a2 | bad | whateversdlsf
a3 | good | something

table B

id | status | a different column to other column above
______________________
b1 | good | lalala
b2 | bad | junk data
b3 | good | not interesting

and what I want is

results

id | status
_________
a1 | good
a2 | bad
a3 | good
b1 | good
b2 | bad
b3 | good

how can I return the rows like this?

I can guarantee that the primary keys of table a & table b never clash

(I am using db2 9.5)
Reply With Quote
  #2 (permalink)  
Old 08-05-09, 21:36
Stealth_DBA Stealth_DBA is offline
Registered User
 
Join Date: May 2009
Posts: 472
gamo, Unless I am missing something, this should work:
Code:
SELECT ID, STATUS
FROM TABLE_A
UNION ALL
SELECT ID, STATUS
FROM TABLE_B
ORDER BY ID, STATUS
I added the ORDER BY to sort the results.
Reply With Quote
  #3 (permalink)  
Old 08-05-09, 21:44
gamo gamo is offline
Registered User
 
Join Date: Jul 2009
Location: Sydney
Posts: 13
ah - union - so obvious...now I feel a bit silly...

thanks!!
Reply With Quote
Reply

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