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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Finding the Non distinct records

Status
Not open for further replies.

JDows

MIS
May 6, 2002
4
US
I am trying to find those records that have duplicate primary key #s so I can delete them.

I can create a query for those that are distinct,
select distinct
from table1

but how do I get the others that are not distinct?
 
eh...

how is it possible that you have a primary key containing duplicates?

in the table, set the field index to not include duplicates...

anyway, back to your problem...
You need something like:

SELECT DISTINCT pKey, count(pKey) FROM tblName WHERE count(pKey) > 1;

this would give you all the pKeys that occur more than once in the table...

if you'd like to delete those records, then put a delete in front of it...

DELETE FROM tblName WHERE pKey = (
SELECT DISTINCT pKey, count(pKey) FROM tblName WHERE count(pKey) > 1
);

fiddling might be required...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top