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
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Counting duplicates

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-05-17 : 09:48:36
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 ct
FROM CompanyContact
GROUP BY company_id
HAVING COUNT(*) > 1


All the contacts for companies with more than one contact:

SELECT *
FROM CompanyContact
WHERE company_id IN (
SELECT company_id
FROM CompanyContact
GROUP BY company_id
HAVING COUNT(*) > 1
)
ORDER BY company_id

Go to Top of Page
   

- Advertisement -