Delete duplicate data in the database and keep a

Delete data, and keep one, rowid pseudo column is reserved for a minimum of data, if there are other needs, can be slightly altered, can retain their own order data.

delete from table_name a
where a.name in
(select name from table_name group by name having count(*) > 1)
and rowid not in
(select min(rowid) from table_name group by name having count(*) > 1)

 

Note: When using the need to replace their table and column names
---------------------
Author: xy Tang and Song
Source: CSDN
Original: https: // blog .csdn.net / weixin_42054155 / article / details / 89337786
copyright: This article is a blogger original article, reproduced, please attach Bowen link!

Guess you like

Origin www.cnblogs.com/niudaxianren/p/11090134.html