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.
Adam writes "I am wanting to see if I have duplicate values in a database. I want to know if a database has more than 1 contact for a company. how would I check for duplicates. Is there a way to do a count so if there is 2 contacts I will know there are 2 contacts?"
Arnold Fribble
Yak-finder General
1961 Posts
Posted - 2006-05-17 : 10:00:38
Generally, this sort of thing.Counts of contacts for companies with more than one contact:
SELECT company_id, COUNT(*) AS ctFROM CompanyContactGROUP BY company_idHAVING COUNT(*) > 1
All the contacts for companies with more than one contact:
SELECT *FROM CompanyContactWHERE company_id IN ( SELECT company_id FROM CompanyContact GROUP BY company_id HAVING COUNT(*) > 1 )ORDER BY company_id