Solved

Finding records that occur more than once in a recordset/table

Posted on 2007-11-19
3
253 Views
Last Modified: 2012-05-05
Need some help with a query.

I have a table called "contacts" which has many fields, in particular, I am interested in contact_email and contact_last_name

I want to create query that will return on records that have contact_email and contact_last_name appearing more than once in the table so I can identify duplicates.

For example,

contact_email          contact_last_name
--------------------------------------------------
john@doe.com        Doe
jane@doe.com        Doe
john@doe.com        Doe

would return

john@doe.com, Doe, 2 based on the logic above thus identifying that John Doe is like a duplicate record.

Please provide actual query.  Thanks.
0
Comment
Question by:ccleebelt
3 Comments
 
LVL 16

Accepted Solution

by:
SQL_SERVER_DBA earned 500 total points
ID: 20314287
select contact_email, contact_last_name
from tablename
group by contact_email, contact_last_name
HAVING COUNT(contact_email)>1 OR COUNT(contact_last_name)>1
0
 

Author Closing Comment

by:ccleebelt
ID: 31409990
Thanks
0
 
LVL 6

Expert Comment

by:wshark83
ID: 20314364
Same query but giving you the number of occurances for Emails and Lastname.

select contact_email, contact_last_name, count(contact_email) as EmailCount, COUNT(contact_last_name) as LastNameCount
from tablename
group by contact_email, contact_last_name
HAVING COUNT(contact_email)>1 OR COUNT(contact_last_name)>1
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Mark Wills Attending one of Rob Farley's seminars the other day, I heard the phrase "The Accidental DBA" and fell in love with it. It got me thinking about the plight of the newcomer to SQL Server...  So if you are the accidental DBA, or, simp…
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question