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

To find the duplicate set of rows


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

New User


Joined: 14 Mar 2009
Posts: 6
Location: Hyderabad

PostPosted: Tue Mar 17, 2009 12:45 pm
Reply with quote

WE HAVE A TABLE WITH X COLUMNS AND THE QUERY IS TO FIND THE
NUMBER OF ROWS WHICH HAVE DUPLICATE VALUES IN
THREE COLUMNS.

FOR EXAMPLE IN TABLE TAB1

WE HAVE FOUR COLUMNS
Code:
COL1      COL2   COL3  COL4
01        342    232   2112
02        342    232   2342
03        342    232   2342
04        342    441   2342

If we Want the number of rows having duplicate values in set of COL2, COL3 AND COL4, the result of the rows query should be like this:

Code:
COL1 , COL2, COL3, COL4
02     342    232  2342
03     342    232  2342


Edited: Please use BBcode when You post some code/error, that's rather readable, Thanks... Anuj

Warning: Turn Off Caps
Back to top
View user's profile Send private message
Succor

New User


Joined: 20 Feb 2009
Posts: 96
Location: Bangalore :)

PostPosted: Tue Mar 17, 2009 3:17 pm
Reply with quote

Rupali,
Try the following Query and let us know if suits your requirement.
Code:
SELECT DISTINCT X.A,X.B,X.C,X.D                             
FROM EMP X ,(SELECT A,B,C,D FROM EMP ) AS Y
WHERE X.B = Y.B                                             
AND   X.C = Y.C                                             
AND   X.D = Y.D                                             
AND   X.A <> Y.A ;

Replace EMP with your table name and A,B,C,D with your respective column names.
WTF
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Tue Mar 17, 2009 3:17 pm
Reply with quote

Hi,

If I understood correctly, try something like:
Code:
select col2,col3, col4, count(*)
from table
group by col2,col3, col4
having count(*) > 1
Back to top
View user's profile Send private message
senthilnathanj

New User


Joined: 31 Jul 2007
Posts: 47
Location: chennai

PostPosted: Tue Mar 17, 2009 5:10 pm
Reply with quote

Hi rupali,
Try the following query and let us know...
Code:
WITH TEMP(COL1,COL2) AS (
SELECT COL1,COL2 FROM TAB1 GROUP BY COL1,COL2 HAVING COUNT(*) > 2)
SELECT A.COL1,A.COL2 FROM TAB1 A WHERE A.COL1 IN (SELECT T.COL1 FROM TEMP T) AND A.COL2 IN (SELECT T.COL2 FROM TEMP T);


u can get the extract output..
Back to top
View user's profile Send private message
gkanswa

New User


Joined: 09 Feb 2009
Posts: 5
Location: Pune

PostPosted: Thu Mar 19, 2009 5:43 pm
Reply with quote

Hi Rupali,

You can try this one -

Code:
Select * from TAB1 A
where 2 <= (select count (distinct Col2) from TAB1
                   where COL2= A.COL2  and
                             COL3 = A.COL3 and
                             COL4= A.COL4);
"Code"d

I don't have mainframe access, so couldn't test it.
Please do correct me if I am wrong.

Girish
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 To get the count of rows for every 1 ... DB2 3
No new posts Duplicate transid's declared using CEDA CICS 3
No new posts To find whether record count are true... DFSORT/ICETOOL 6
No new posts Exclude rows with > than x occurre... DFSORT/ICETOOL 6
No new posts Find the size of a PS file before rea... COBOL Programming 13
Search our Forums:

Back to Top