Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Finding duplicate rows by matching multiple fields

Author  Topic 

TimeIsShort
Starting Member

2 Posts

Posted - 2011-04-20 : 19:18:41
Good day all,

My question pertains to a table similar to the one below. Consider an employee table with the following data (first row header) and no primary key:

FirstName,LastName,Email,Telephone
John,Doe,j.doe@somewhere.com,9991231234
J,Doe,j.doe@somewhere.com,9991231234
Jonathan,Doe,j.doe@somewhere.com,9991231234
Jane,Doe,jane.doe@somewhere.com,9993214321

Given such a table, what is the correct SQL syntax (SQL Server 2000) that would return the first three row (i.e. disregards first name, and returns rows with duplicate last name AND email AND telephone)?

Thank you to all in advance.

singularity
Posting Yak Master

153 Posts

Posted - 2011-04-20 : 19:42:02
[code]
select *
from employee a
where exists (select LastName, Email, Telephone
from employee b
where a.LastName = b.LastName and
a.Email = b.Email and
a.Telephone = b.Telephone
group by LastName, Email, Telephone
having count(*) > 1)
[/code]
Go to Top of Page

TimeIsShort
Starting Member

2 Posts

Posted - 2011-04-21 : 10:30:59
Thank you. Worked like a charm.
Go to Top of Page

Maqsood
Starting Member

1 Post

Posted - 2012-10-09 : 04:21:39
Initial obsrvation is under way so I woukd like to suggest u please wait for sometimw.
Thanks

Muhammed Maqsood |Application Support Team Member (ASG)|TCS
Springboard BAM/EDW | EIP | AS&M |Service Infrastructure| BT Operate
Plot B1, Block EP & GP, Sector - V, Salt Lake Electronics Complex, Kolkata - 700091 INDIA
Office : +91 33 - 66366197 | Mobile : +91 90383 48889
Mailto: muhammed.alam@tcs.com
Website: http://www.tcs.com
Experience certainty. IT Services
Business Solutions
Outsourcing
Go to Top of Page
   

- Advertisement -