Jun 24, 2004 #1 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?
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?
Jun 24, 2004 #2 Crowley16 Technical User Jan 21, 2004 6,931 GB 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... Upvote 0 Downvote
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...