(一)
select * from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) >
delete from people
where peopleId in (select peopleId from people group by peopleId having count(peopleId) >
and rowid not in (select min(rowid) from people group by peopleId having count(peopleId )>
select * from vitae a
where (a
delete from vitae a
where (a
and rowid not in (select min(rowid) from vitae group by peopleId
select * from vitae a
where (a
and rowid not in (select min(rowid) from vitae group by peopleId
(二)
比方說
在A表中存在一個字段“name”
而且不同記錄之間的“name”值有可能會相同
現在就是需要查詢出在該表中的各記錄之間
Select Name
如果還查性別也相同大則如下:
Select Name
(三)
方法一
declare @max integer
declare cur_rows cursor local for select 主字段
open cur_rows
fetch cur_rows into @id
while @@fetch_status=
begin
select @max = @max
set rowcount @max
delete from 表名 where 主字段 = @id
fetch cur_rows into @id
end
close cur_rows
set rowcount
方法二
有兩個意義上的重復記錄
select distinct * from tableName
就可以得到無重復記錄的結果集
如果該表需要刪除重復的記錄(重復記錄保留
select distinct * into #Tmp from tableName
drop table tableName
select * into tableName from #Tmp
drop table #Tmp
發生這種重復的原因是表設計不周產生的
假設有重復的字段為Name
select identity(int
select min(autoID) as autoID into #Tmp
select * from #Tmp where autoID in(select autoID from #tmp
最後一個select即得到了Name
(四)
查詢重復
select * from tablename where id in (
select id from tablename
group by id
having count(id) >
)
select * from vitae a
where (a
運行會產生問題
From:http://tw.wingwit.com/Article/program/MySQL/201311/29563.html