IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Problem in finding duplicates between 2 tables


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sgiri
Warnings : 1

New User


Joined: 07 Aug 2007
Posts: 20
Location: chennai

PostPosted: Mon Aug 13, 2007 3:09 pm
Reply with quote

Hi all ,
I have problem in finding duplicates between 2 tables. Let the 2 tables be A - ( active ) & B - (Archive). A - has 6 columns and 3 indexes . While B has 7 columns and 4 indexes.

Can any one suggest me some query to find out such duplicates between A and B?

NOTE : A DUPLICATE IN OUR CONTEXT MEANS A SAME ROW EXISTING IN BOTH 'A' & 'B'.
Back to top
View user's profile Send private message
Prajesh_v_p

Active User


Joined: 24 May 2006
Posts: 133
Location: India

PostPosted: Mon Aug 13, 2007 3:27 pm
Reply with quote

Why cant you just try a select with join between these tables A and B on columns you want to find out duplicates?
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 631
Location: Wisconsin

PostPosted: Mon Aug 13, 2007 6:28 pm
Reply with quote

Well, none of the rows will be the same. Table B has an extra column. Do the tables have identical primary keys?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19243
Location: Inside the Matrix

PostPosted: Mon Aug 13, 2007 9:20 pm
Reply with quote

Hello,

It may help if you provide a better definition of "duplicate".

It may also be easier and maybe even faster to unload the tables and do your comparison in batch against the sequential files.
Back to top
View user's profile Send private message
stodolas

Active Member


Joined: 13 Jun 2007
Posts: 631
Location: Wisconsin

PostPosted: Mon Aug 13, 2007 9:38 pm
Reply with quote

It also depends on what you plan on doing with those duplicates. Are you wanting to delete duplicates, process something based on that 7th column, or just identify them?

Simply identifying them is fairly simple with some SQL. Be sure to match the WHERE so the columns of the primary key are the first matched, then work through the indexes and end with those columns that aren't part of any index.
Code:

Select A.C1,A.C2,A.C3,A.C4,A.C5,A.C6, B.C1,B.C2,B.C3,B.C4,B.C5,B.C6,B.C7
From A, B
WHERE A.C1 = B.C1, A.C2=B.C2, etc
Back to top
View user's profile Send private message
sgiri
Warnings : 1

New User


Joined: 07 Aug 2007
Posts: 20
Location: chennai

PostPosted: Tue Aug 14, 2007 10:17 am
Reply with quote

Thank you stoldas what you have said worked out ... Thank you !!
Back to top
View user's profile Send private message
View previous topic : : View next topic  
Post new topic   Reply to topic All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Question regarding ISPF tables with T... TSO/ISPF 11
No new posts To join 2 tables and to join 3rd tabl... DB2 8
No new posts Problem moving a cobol program into E... COBOL Programming 3
No new posts Finding and researching jobs All Other Mainframe Topics 0
No new posts VB to FB - Finding LRECL SYNCSORT 4
Search our Forums:


Back to Top