sql - Delete rows with duplicate value in one column but different value in other columns -


i have table 3 columns :

id, name, role 

some names duplicated have unique id, how delete rows duplicated name(not all,leave 1 each) in table?

group name , select lowest unique id. delete records not in list

delete your_table id not in (   select min(id)    your_table   group name ) 

and if use mysql need subquery since mysql not allow delete same table selecting from:

delete your_table id not in (   select *    (     select min(id)      your_table     group name   ) tmp_tbl ) 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

jsf - How to ajax update an item in the footer of a PrimeFaces dataTable? -

django - CSRF verification failed. Request aborted. CSRF cookie not set -