mysql刪除重複資料

2022-08-23 13:09:12 字數 639 閱讀 5725

id         姓名  課程名稱 分數

1         張三     數學    69

2          李四        數學    89

3          張三        數學    69

刪除除了自動編號不同,其他都相同的學生冗餘資訊

完整的sql語句如下:

delete from tablename where id not in (select bid from (select min(id) as bid from tablename group by name,kecheng,fenshu) as b ) ;

解釋:select bid from (select min(id) as bid from tablename group by name,kecheng,fenshu) as b

這個子查詢的目的是從b中列出講篩選結果,即bid的集合。

(select min(id) as bid from tablename group by name,kecheng,fenshu) as b

將分組結果中的最小的bid當做乙個心的集合當做乙個心的子表b,

注意mid(id)一定要有乙個別名,這裡取的是bid,作為b的乙個列名,因為在上一級查詢中要用到這個列名

mysql刪除重複資料

最近遇到刪除重複資料的問題,先分享一下解決辦法,如有不完善之處還望包涵!舉例如下 mysql select from table03 id name degree 1 fly 90 2 fly 90 3 fly 90 4 fly 80 5 wang 90 6 wang 90 7 wang 90 8 ...

MySQL 刪除重複資料

建表,插入資料,當然如果你不想測試一下,也可以直接用後面的刪除語句 create table if not exists tb01 id int unsigned primary key auto increment,name varchar 10 not null insert into tb01...

刪除重複資料

介紹兩種刪除重複行的方式 1.使用臨時表,分組找出重複部分的id進行刪除 刪除table goods info 中存在重複goods id的記錄 select identity int,1,1 as autoid,into temptable from goods info select min a...