a sample for deleting duplicated records

delete from make_all where make_id in
(
    select inn.make_id from
    (
        select a.make_id from make_all a,
        (    
            select make_name_short, min(make_id) make_id, count(1)
            from make_all group by make_name_short having count(1)>1
        ) b
        where a.make_id!=b.make_id
        and a.make_name_short=b.make_name_short
    ) inn

)


the procedure is

1) select all the records with a non-single count, along with the minimum id whose record you want to reserve.

2) select the records you want to delete(eg. non-single, non-minimum id).

3) delete the records with the specific id.

你可能感兴趣的:(a sample for deleting duplicated records)