mysql - Find duplicates based on two fields and delete them -


i have table called tourn_results there multiple records share same tournamentid.

example of tourn_result record set

uniqueid tournamentid playerrank 1        111          1 2        111          2 3        111          3  4        222          1 5        222          2 6        222          3  7        333          1 8        333          2 9        333          3 10       333          4  11       111          1 12       111          2 13       111          3 

for each tournament there cannot more 1 playerrank = 1 (only 1 first place per tournamentid)

i need to find each duplicate , delete them, can't find suitable answer. appreciate help.

this delete rows lowest uniqueid each combination of (tournamentid,playerrank).

delete tourn_results x uniqueid <> ( select min(y.uniqueid)                       tourn_results y                      y.tournamentid = x.tournamentid                        , y.playerrank = x.playerrank  ); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -