Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find Duplicate rows

Status
Not open for further replies.

mcauliff

Programmer
Feb 26, 2007
71
US
I have a DB2 v7 table, that I need to find duplicate email addresses. The primary key to the table is a autogenerated number.

How would I code the SQL to perform this task? I have tried a join and subselect, but didn't work or return multiple rows.

 
mcauliff,

Howabout?
Code:
SELECT EMAIL_ADDR, COUNT(*)
FROM EMAIL_TAB
GROUP BY EMAIL_ADDR
HAVING COUNT(*) > 1

Marc
 
Thank you for the reply.

I resolved it with the following SQL

SELECT EMAIL_ID
,FIRST_NM || ' ' || LAST_NM
,CLIENT_NO
,CNTC_NO
FROM Table
WHERE (EMAIL_ID) IN
(
SELECT EMAIL_ID FROM Table
GROUP BY EMAIL_ID
 
mcauliff,

A couple of points:
a) Your SQL is missing a bracket (after the subselect I suspect)
b) doesn't that give you a list of ALL email addresses, removing the duplicates, which is not what I believe you asked for.

Pleased that you found an answer though, congrats and thanks for letting us know.

Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top