Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I query to find duplicates

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
US
I have a table with two columns:

Table: RaceStock
Columns: HorseName, Breed

The customer says the HorseName can be duplicate if breed is diferent.

The table is huge so I need an efficient query that gives me HorseName and Breed where HorseName occurs on more than one row. I guess it is the opposite of a SELECT DISTINCT.

I'm stumped; any help is appreciated.

Thanks
Lyndon
 
Thanks Leslie, that gives me my Horse Names but no breed column that I will need for my output.

Any ideas?

Lyndon
 


SELECT HorseName, Breed FROM RaceStock
GROUP BY HorseName
HAVING Count(HorseName) > 1
 
SELECT A.HorseName, A.Breed
FROM RaceStock AS A INNER JOIN (
SELECT HorseName FROM RaceStock GROUP BY HorseName HAVING Count(*)>1
) AS G ON A.HorseName = G.HorseName

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top