SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Finding duplicate rows by matching multiple fields
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

TimeIsShort
Starting Member

2 Posts

Posted - 04/20/2011 :  19:18:41  Show Profile  Reply with Quote
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

151 Posts

Posted - 04/20/2011 :  19:42:02  Show Profile  Reply with Quote

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)

Go to Top of Page

TimeIsShort
Starting Member

2 Posts

Posted - 04/21/2011 :  10:30:59  Show Profile  Reply with Quote
Thank you. Worked like a charm.
Go to Top of Page

Maqsood
Starting Member

India
1 Posts

Posted - 10/09/2012 :  04:21:39  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000