sql刪除同一個(gè)表的重復(fù)數(shù)據(jù)

數(shù)據(jù)如下,表名video,發(fā)現(xiàn)vid和section_id重復(fù)的數(shù)據(jù)很多,要?jiǎng)h除重復(fù)的數(shù)據(jù)只保留一條

+----------+-----------+------------+
| video_id | vid       | section_id |
+----------+-----------+------------+
|    10908 | 284478110 |  528238111 |
|    10909 | 284478110 |  528248111 |
|    10884 | 278748110 |  528048111 |
|    10885 | 278758110 |  528058111 |<-重復(fù)
|    54155 | 278758110 |  528058111 |<-重復(fù)
|    10886 | 278768110 |  528068111 |
|    54156 | 278768110 |  528068111 |
|    10887 | 278778110 |  528078111 |
|    10888 | 282228110 |  528078111 |
|    54157 | 278778110 |  528078111 |
|    54158 | 282228110 |  528078111 |
|    10889 | 282148110 |  528088111 |
|    54159 | 282148110 |  528088111 |
|    10890 | 282158110 |  528098111 |
|    54160 | 282158110 |  528098111 |
|    10891 | 282168110 |  528108111 |
|    54161 | 282168110 |  528108111 |
|    10892 | 282178110 |  528118111 |
|    10893 | 282238110 |  528118111 |
|    54162 | 282178110 |  528118111 |
+----------+-----------+------------+

如果要保留小id的數(shù)據(jù):

delete a from video a,video b where a.video_id>b.video_id and a.vid=b.vid and a.section_id=b.section_id

eg.

update ms_video a,ms_video b set a.status=0 where a.section_id=b.section_id and a.vid=b.vid and a.`status`=1 and b.`status`=1 and a.video_id<b.video_id; //video_id 為自增id
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容