sql查詢數據庫表中重復數值
-- 查詢表中id重復的值
select id from 表名 group by id having count(*) > 1
--查詢表中的重復記錄,重復記錄是根據id重復做判定
select * from 表名 where id in(select id from 表名 group by id having count(*) > 1)
-- 刪除表中多余的重復記錄,重復記錄根據id重復做判定,只留rowid最小的那條記錄
delete from 表名 where (id) in (select id from 表名 group by id having count(id) > 1) and rowid not in(select min(rowid) from group by id having count(*) > 1)
-- 查找表中多余的重復記錄(多個字段)
select * from 表名 a where (a.id,a.name) in (select id, name from 表名 group by id,name having count(*) > 1)
-- 查詢表中多余的重復記錄(多個字段),不包含rowid最小的記錄
select * from 表名 a where (a.id,a.name) in (select id,name from 表名 group by id,name having count(*) > 1) and rowid not in (select min(rowid) from 表名 group by id,name having count(*) > 1)