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
 Query for duplicates in table

Author  Topic 

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2012-03-14 : 15:24:58
I have a table where multiple records have been duplicated and I need to return results based on two criteria, the Name of the person and the Street Address Line 1. I am not sure if the query is accurate because it returns the same results as when I just use one criteria:


Select
tName,
tCity,
tPhone,
tStreetLine1
from
tblObjectType20005
Group by
tName,
tCity,
tPhone,
tStreetLine1
Having(COUNT(tName)>1) and (COUNT(tStreetLine1)>1)

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-03-14 : 15:34:32
The code you posted does not parse - the where condition is not complete. So not quite clear to me what the requirement is. Would this do it?
SELECT
tName,
tCity,
tPhone,
tStreetLine1
FROM
tblObjectType20005 a
WHERE
EXISTS
(
SELECT 1 FROM tblObjectType20005 b WHERE a.tName = b.tName AND a.tStreetLine1 = b.tStreetLine1
HAVING COUNT(*) > 1
)
Go to Top of Page

meberg66219
Yak Posting Veteran

65 Posts

Posted - 2012-03-14 : 15:38:15
I realized that I had posted the incorrect code and have corrected my errors. Thank you for the quick response as the query you have posted is successful.
Go to Top of Page
   

- Advertisement -