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

How to pick the duplicates without a primary key


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
syed-sameer-ahmed
Warnings : 2

New User


Joined: 22 Feb 2007
Posts: 45
Location: Bangalore

PostPosted: Tue Aug 11, 2009 4:42 pm
Reply with quote

Hello All,

I have a table which has NO primary Key and it has many fields which are duplicates.I want to fetch the customer id from this table

for ex

Code:
Customer id      Tin   pin    Add      code        level
----------------------------------------------------------

1234                 1     2         3         4             5
987A                 1     2         3         4             5
A125                 45   46        77      88            99
B123                 45   46        77      88            99
HERD                 45  46        77      88             99 
Code'd


This table has 99167 records and there are many records in similar format but different duplicate data..

Now I have to fetch those customer Id whose TIn,pin,add,code,level are duplicates.

Please suggest.
Back to top
View user's profile Send private message
d_pansare

New User


Joined: 25 Apr 2009
Posts: 20
Location: Pune

PostPosted: Tue Aug 11, 2009 6:16 pm
Reply with quote

You can write self join query given below:

Select A.customer id from table a, table b where
a.customerid <> b.customerid and a.tin = b.tin;

you can use similar queries for rest of the fields. You can even add the rest of conditions in the same query.

I hope this will work for you..

Thanks
Dipak
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Tue Aug 11, 2009 6:30 pm
Reply with quote

Hi Sayed,

You can try the following query.

Select Customer
From t1 a
Where
(select count(*) from t1 b
Where a.Tin = b.Tin and
a.pin = b.pin and
a.add = b.add and
a.code = b.code and
a.level = b.level) > 1;
Back to top
View user's profile Send private message
syed-sameer-ahmed
Warnings : 2

New User


Joined: 22 Feb 2007
Posts: 45
Location: Bangalore

PostPosted: Thu Aug 13, 2009 5:54 pm
Reply with quote

Actually its only one table and I have to fetch records which are duplicate in the same table.And the records are next to each other.

Code:


Customer id      Tin   pin      Add      code        level
----------------------------------------------------------

1234                 1     2         3       4             5
987A                 1     2         3       4             5
A125                45    46        77       88            99
B123                45    46        77       88            99
HERD                45    46        77       88            99
B123                12    23        45       56            66
HERD                12    23        45       56            66
CATS                1      2         3       4              5



Now I need to compare 1 record with record 2 and last record...

I had an idea to first record first and put in Working storage var and fetch the 2nd record and put it in another Working Storage var and then compare..

i do not know how to fetch the second record after fetching first record and it should be followed till SQL=+100
Back to top
View user's profile Send private message
Srihari Gonugunta

Active User


Joined: 14 Sep 2007
Posts: 295
Location: Singapore

PostPosted: Thu Aug 13, 2009 5:56 pm
Reply with quote

Syed, The query given is for single table only. That would avoid all the programming for you. Just declare cursor and fetch data.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Aug 13, 2009 7:10 pm
Reply with quote

Hello,

Quote:
Actually its only one table
Yes, the table would be joined to itself using only one "real" table, but logically it is 2 tables (table a and table b).
Back to top
View user's profile Send private message
syed-sameer-ahmed
Warnings : 2

New User


Joined: 22 Feb 2007
Posts: 45
Location: Bangalore

PostPosted: Thu Aug 13, 2009 7:40 pm
Reply with quote

I tried executing your query but It was taking lot of time,almost 3 hours.

ANy other suggestions ? Ill try your query again. but more ideas are approciated.

Thanks in advance.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


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

PostPosted: Thu Aug 13, 2009 9:44 pm
Reply with quote

Hello,

Quote:
but It was taking lot of time,almost 3 hours.
Yes, rather small amounts of "innocent looking" code can consume vast amounts of system resources.

How many rows are in the table?
Back to top
View user's profile Send private message
ashimer

Active Member


Joined: 13 Feb 2004
Posts: 551
Location: Bangalore

PostPosted: Fri Aug 14, 2009 8:49 pm
Reply with quote

Quote:


I had an idea to first record first and put in Working storage var and fetch the 2nd record and put it in another Working Storage var and then compare..



Good Idea ..use order by all the cols in your cursor and then check each record one by one ...
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Query on edit primary command CLIST & REXX 5
No new posts Query on edit primary command CLIST & REXX 1
No new posts Cobol prog to put an indicator on the... JCL & VSAM 1
No new posts How to remove block of duplicates DFSORT/ICETOOL 8
This topic is locked: you cannot edit posts or make replies. Compare files with duplicates in one ... DFSORT/ICETOOL 11
Search our Forums:

Back to Top