1. select id from (select min(id) AS id from table group by code) a;
2. delete from table where id not in (select id from (select min(id) AS id from table group by code) a)
1. select id from (select min(id) AS id from table group by code) a;
2. delete from table where id not in (select id from (select min(id) AS id from table group by code) a)