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

How do I find out those duplicates using SQL


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

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Wed Sep 17, 2008 8:21 am
Reply with quote

Hi,

I have this requirement:
The DB2 tables looks like this
Feild A
Feild B
Feild C

In these feilds we have some duplicates.
How do I find out those duplicates. ?
Can this be done with an SQL ?
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: Wed Sep 17, 2008 8:55 am
Reply with quote

Hello,

If you post some sample rows and show the output you want when those rows are processed, someone will be able to make suggestions.

As posted, your question is not clear.
Back to top
View user's profile Send private message
ap_mainframes

Active User


Joined: 29 Dec 2005
Posts: 181
Location: Canada

PostPosted: Wed Sep 17, 2008 9:33 am
Reply with quote

Hello,
This is how my DB2 table looks like

Feild A Feild B Feild C
Tom Toronto Postalcode1
Tom Toronto Postalcode1
Tom Toronto Postalcode1
Harry Montreal Postalcode2
Harry Montreal Postalcode2


My output should be

Tom Toronto Postalcode1
Tom Toronto Postalcode1
Tom Toronto Postalcode1
Harry Montreal Postalcode2
Harry Montreal Postalcode2

Please note that I cant hardcode these values in where clause.
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: Wed Sep 17, 2008 11:26 am
Reply with quote

Hello,

Your sample data does not deal with selecting duplicates. . . A simple SELECT * with no WHERE would get that result.

Suggest you post more representative data including some rows that would not be selected as well as some that would.
Back to top
View user's profile Send private message
Cristopher

New User


Joined: 31 Jul 2008
Posts: 53
Location: NY

PostPosted: Wed Sep 17, 2008 2:12 pm
Reply with quote

ap,
as Dick has indicated your requirement is not clear enough to suggest a solution.
If you wish to identify only the duplicates in the table on all the 3 fields thn this query might help
Code:

SELECT A,B,C FROM SAMPLE_TABLE 
GROUP BY A,B,C                           
HAVING COUNT(*) > 1;
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 find whether record count are true... DFSORT/ICETOOL 6
No new posts Find the size of a PS file before rea... COBOL Programming 13
No new posts Find the occurrence of Key Field (Par... DFSORT/ICETOOL 6
No new posts Find a record count/numeric is multip... COBOL Programming 1
No new posts How to remove block of duplicates DFSORT/ICETOOL 8
Search our Forums:

Back to Top