Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
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, tStreetLine1from tblObjectType20005Group by tName, tCity, tPhone, tStreetLine1Having(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, tStreetLine1FROM tblObjectType20005 aWHERE EXISTS ( SELECT 1 FROM tblObjectType20005 b WHERE a.tName = b.tName AND a.tStreetLine1 = b.tStreetLine1 HAVING COUNT(*) > 1 )
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.