91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點擊 登錄注冊 即表示同意《億速云用戶服務條款》

MySQL中如何刪除表重復記錄

發布時間:2021-08-02 16:22:17 來源:億速云 閱讀:141 作者:Leah 欄目:MySQL數據庫

本篇文章給大家分享的是有關MySQL中如何刪除表重復記錄,小編覺得挺實用的,因此分享給大家學習,希望大家閱讀完這篇文章后可以有所收獲,話不多說,跟著小編一起來看看吧。

創建實驗表student表數據:
mysql> use test
Database changed
mysql> create table student (id int,name varchar(10));
Query OK, 0 rows affected (1.67 sec)

mysql> insert into student values (11,'aa');
Query OK, 1 row affected (0.26 sec)


mysql> insert into student values (12,'aa');
Query OK, 1 row affected (0.07 sec)


mysql> insert into student values (13,'aa');
Query OK, 1 row affected (0.12 sec)


mysql> insert into student values (14,'aa');
Query OK, 1 row affected (0.11 sec)


mysql> insert into student values (15,'bb');
Query OK, 1 row affected (0.19 sec)


mysql> insert into student values (16,'bb');
Query OK, 1 row affected (0.14 sec)


mysql> insert into student values (17,'cc');
Query OK, 1 row affected (0.15 sec)


mysql> select * from student;
+------+------+
| id   | name |
+------+------+
|   11 | aa   |
|   12 | aa   |
|   13 | aa   |
|   14 | aa   |
|   15 | bb   |
|   16 | bb   |
|   17 | cc   |
+------+------+
7 rows in set (0.22 sec)


方法1:
mysql>  create temporary table temp as select min(id),name from student group by name;
Query OK, 3 rows affected (0.18 sec)
Records: 3  Duplicates: 0  Warnings: 0


mysql> truncate table student;
Query OK, 0 rows affected (0.40 sec)


mysql> insert into student select * from temp;
Query OK, 3 rows affected (0.11 sec)
Records: 3  Duplicates: 0  Warnings: 0


mysql> select * from student;
+------+------+
| id   | name |
+------+------+
|   11 | aa   |
|   15 | bb   |
|   17 | cc   |
+------+------+
3 rows in set (0.00 sec)


mysql> drop temporary table temp;
Query OK, 0 rows affected (0.17 sec)


方法2:
mysql> create temporary table temp as select min(id) as MINID from student group by name;
Query OK, 3 rows affected (0.24 sec)
Records: 3  Duplicates: 0  Warnings: 0


mysql> delete from student where id not in (select minid from temp);
Query OK, 4 rows affected (0.07 sec)


mysql> select * from student;
+------+------+
| id   | name |
+------+------+
|   11 | aa   |
|   15 | bb   |
|   17 | cc   |
+------+------+
3 rows in set (0.00 sec)


方法3:
mysql> delete from student where id not in (select minid from (select min(id) as minid from student
group by name) b);
Query OK, 4 rows affected (0.19 sec)


mysql> select * from student;
+------+------+
| id   | name |
+------+------+
|   11 | aa   |
|   15 | bb   |
|   17 | cc   |
+------+------+
3 rows in set (0.00 sec)


以上就是MySQL中如何刪除表重復記錄,小編相信有部分知識點可能是我們日常工作會見到或用到的。希望你能通過這篇文章學到更多知識。更多詳情敬請關注億速云行業資訊頻道。

向AI問一下細節

免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。

AI

平谷区| 河曲县| 曲阜市| 美姑县| 新竹县| 宣武区| 阆中市| 远安县| 宁武县| 彝良县| 高青县| 娱乐| 西华县| 句容市| 石景山区| 商南县| 弋阳县| 新河县| 绥中县| 满洲里市| 临沧市| 抚松县| 临清市| 中宁县| 大庆市| 凤山市| 岳阳市| 新兴县| 和田市| 汝州市| 崇明县| 海口市| 许昌县| 砀山县| 五指山市| 罗定市| 松滋市| 芮城县| 钦州市| 阳信县| 嘉义县|