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)
 select duplicate records only.

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2003-09-24 : 08:11:52
pete writes "I'm looking to select upc_num from a table. I only want the duplicate entries. Is there a way to incorporate Count() so I can pick upc_num with more than 1 entry or 3 entries?

New to SQL so any help is great help."

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-09-24 : 08:14:04
SELECT upc_num FROM myTable GROUP BY upc_num HAVING Count(*)>1

You can change the number in the HAVING clause to match however many duplicate rows you want to identify. If you want the actual rows returned, put the above into a subquery:

SELECT * FROM myTable WHERE upc_num IN(SELECT upc_num FROM myTable GROUP BY upc_num HAVING Count(*)>1)
Go to Top of Page
   

- Advertisement -