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
 Duplicate records

Author  Topic 

iradev
Starting Member

45 Posts

Posted - 2010-06-17 : 06:23:12
I did some changes to my db so requirements changed as following:
I have the following tables: Clients and Locations. Both tables are linked by LocationId which I don't need in the select statement.

I want to find duplicates that have BOTH, the same Clients.RegNo and the same Locations.Code

I want to include the following columns in my select statement: Clients.ClientId, Clients.Company, Clients.RegNo, Locations.Code, NumOfOccurances

Any ideas/help?

p.s. Peso's answer was for my previous requirements.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2010-06-17 : 06:25:16
[code]SELECT c.RegNo,
l.PostCode,
COUNT(*)
FROM Client AS c
INNER JOIN Location AS l ON l.ClientID = c.ClientID
GROUP BY c.RegNo,
l.PostCode
HAVING COUNT(*) > 1[/code]

N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page
   

- Advertisement -