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 > To compare two tables in db2

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-03-11, 00:48
Sajeev Sajeev is offline
Registered User
 
Join Date: Aug 2011
Posts: 10
To compare two tables in db2

what is the query to compare values in two different tables which contains same column name and datatype?
Eg:
TAB1
ID COL1 COl2 Col3
1 A A A
2 B B B
3 C C C
4 A A A

TAB2
ID COL1 COl2 Col3
1 A A A
2 B B B
3 C D C
4 A A A


Output should be :

ID COL1 COl2 Col3
3 C C C
3 C D C
Reply With Quote
  #2 (permalink)  
Old 08-03-11, 00:59
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
A little modification for an example by Peter in this thread may give you an answer.
To compare two tables in db2

Last edited by tonkuma; 08-03-11 at 01:13.
Reply With Quote
  #3 (permalink)  
Old 08-03-11, 04:09
Sajeev Sajeev is offline
Registered User
 
Join Date: Aug 2011
Posts: 10
Thanks fro ur reply..
I got this doubt solved with this query.. Peter's query was also working fine..

SELECT ID,COL1,COl2,COl3,count(*)
FROM
(


SELECT A.ID, A.COL1,A.COL2,A.COL3
FROM TAB1 A

UNION ALL

SELECT B.ID, B.COL1,B.COL2,B.COL3

FROM TAB2 B
) TMPTBL
GROUP BY
ID,COL1,COL2,COl3

HAVING COUNT(*) <> 2
ORDER BY ID
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