mysql刪除重復行的實現方法
更新時間:2018年06月29日 11:17:18 作者:勇敢的飛石
這篇文章主要介紹了mysql刪除重復行的實現方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
表relation
create table relation( id int primary key auto_increment, userId int not null, fanId int not null );
插入幾條數據
insert into relation(userId,fanId) values(1,1) ,(1,1) ,(1,1), (2,2),(2,2) ,(3,3),(3,3);
表中的數據
id | userId | fanId |
---|---|---|
1 | 1 | 1 |
2 | 1 | 1 |
3 | 1 | 1 |
4 | 2 | 2 |
5 | 2 | 2 |
6 | 3 | 3 |
7 | 3 | 3 |
去重
delete t from relation s join relation t using(userId,fanId) where s.id<t.id;
總結
以上所述是小編給大家介紹的mysql刪除重復行的實現方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
相關文章
MySQL中索引優(yōu)化distinct語句及distinct的多字段操作
這篇文章主要介紹了MySQL中索引優(yōu)化distinct語句及distinct的多字段操作方法,distinct語句去重功能的使用是MySQL入門學習中的基礎知識,需要的朋友可以參考下2016-01-01MySQL 5.7.9 服務無法啟動-“NET HELPMSG 3534”的解決方法
這篇文章主要介紹了MySQL 5.7.9 服務無法啟動-“NET HELPMSG 3534”的解決方法,需要的朋友可以參考下2016-12-12MySql總彈出mySqlInstallerConsole窗口的解決方法
這篇文章主要介紹了MySql總彈出mySqlInstallerConsole窗口的解決方法,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-09-09