mysql刪除重復行的實現(xiàn)方法
更新時間:2018年06月29日 11:17:18 作者:勇敢的飛石
這篇文章主要介紹了mysql刪除重復行的實現(xiàn)方法,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
表relation
create table relation( id int primary key auto_increment, userId int not null, fanId int not null );
插入幾條數(shù)據
insert into relation(userId,fanId) values(1,1) ,(1,1) ,(1,1), (2,2),(2,2) ,(3,3),(3,3);
表中的數(shù)據
| 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刪除重復行的實現(xiàn)方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網站的支持!
相關文章
Mysql之EXPLAIN顯示using filesort介紹
EXPLAIN 是mysql解釋select查詢的一個關鍵字,可以很方便的用于調試2012-02-02

