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

To retreive only duplicates


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

New User


Joined: 26 Dec 2007
Posts: 8
Location: Chennai

PostPosted: Thu Jan 31, 2008 11:03 am
Reply with quote

Hi,
I have a table which contains 3 columns which can allow duplicates. Now i want to write a query so that i want to retreive ONLY DUPLICATES for all the columns.

Thnaks in Advance,
Vijay
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 Jan 31, 2008 9:13 pm
Reply with quote

Hello,

How many rows are in the table?

What if there are more than 2 rows that have all 3 columns duplicated? Do you want to retrieve ALL of the duplicates or only those rows that are not the "first" row for a particular set of values (i.e. if 2 rows match, do you want both selected or only 1 - if 3 rows match, do you want all 3 or only 2)?
Back to top
View user's profile Send private message
bbessa

New User


Joined: 03 Aug 2006
Posts: 13
Location: Brazil

PostPosted: Fri Feb 01, 2008 2:58 am
Reply with quote

Hi.

Assuming you just want to show distinct rows that are duplicated and a row count for how many duplicates exist:

Code:

SELECT COL1, COL2, COL3, ROWCOUNT FROM
(
  SELECT DISTINCT COL1,COL2,COL3,COUNT(*) AS ROWCOUNT
  FROM OWNER.TABLE
  GROUP BY COL1,COL2,COL3
 ) AS T
WHERE ROWCOUNT > 1


I don't really know if it's the best solution but it does the job.

If the results provided by this query are not what you wanted then you might want to look into mr. scherrer's questions in the previous post and supply more details on your demand.

My regards,

Bernardo
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 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
No new posts Merging 2 files but ignore duplicate... DFSORT/ICETOOL 1
No new posts COUNT the number of duplicates DFSORT/ICETOOL 3
This topic is locked: you cannot edit posts or make replies. SUM FIELDS=NONE in reverse - Get dupl... DFSORT/ICETOOL 9
Search our Forums:

Back to Top