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 Rhinorhino 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 find duplicate field values easily?

SQL Syntax

How do I find duplicate field values easily?

by  JDurbin  Posted    (Edited  )
This example uses the customer table from Tastrade
[tt]USE ADDBS(_SAMPLES)+"tastrade\data\customer"[/tt]
Find duplicate fields
General syntax:
[tt]SELECT COUNT(MyField) - 1 as Dupes, MyField ;
FROM MyTable ;
GROUP BY MyField ;
HAVING COUNT(MyField) > 1 ;
ORDER BY Dupes DESCENDING ;
INTO CURSOR cDuplicates[/tt]
Example:[tt]
SELE COUNT(country) - 1 as Dupes, country ;
FROM customer ;
HAVING COUNT(country) > 1 ;
ORDER BY Dupes DESC ;
GROUP BY country[/tt]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top