查詢以及刪除一個數據庫表內的重復數據。
1.查詢表中的多余的重復記錄,重復記錄是根據單個字段來判斷的。
select * from biao where id in (select id from biao group by id having count(id) >1 )
2.刪除表中的多余的重復記錄,重復記錄是根據(id)來判斷,只留rowid 最小值。
delete from biao where id in ( select id from biao group by id having count(id) ) and rowid not in ( select min(rowid) from biao group by id having count(id)>1 )
delete from xuesheng
where T_NAME in
(select T_NAME
from xuesheng
group by T_NAME, T_ADDRESS, T_PHONE, T_BIRTHDAY
having count(*) > 1) --重復數據
and rowid not in
(select max(rowid)
from xuesheng
group by T_NAME, T_ADDRESS, T_PHONE, T_BIRTHDAY
having count(*) > 1) --保留一條重復數據
3.刪除表中重復的記錄(多個字段),
delete from xuesheng
where T_NAME in
(select T_NAME
from xuesheng
group by T_NAME, T_ADDRESS, T_PHONE, T_BIRTHDAY
having count(*) > 1) --不保留重復數據
來自:https://www.cnblogs.com/252e/archive/2012/09/13/2682817.html