Jump to content

Selecting duplicate rows


dreamwest

Recommended Posts

So which fields are duplicated? This is key to the query.

I'll take a guess:

 

SELECT p1.id, p1.title, p2.id, p2.title
FROM photo p1
JOIN photo p2 ON p1.title = p2.title AND p2.id != p1.id

 

The above should give you all the id's (assuming "id" is the name of your primary key) and title's of duplicated records.

 

This also points to an issue with indexes. If your titles need to be unique make sure your application checks for duplicate titles before it starts the insert, AND you have a UNIQUE index on the title field, to stop duplicate entries.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.