程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> mysql如何快速刪除重復的數據

mysql如何快速刪除重復的數據

編輯:MySQL綜合教程

mysql如何快速刪除重復的數據


在mysql中去重,其實是一個很簡單的事情,來看下面的例子:

mysql> DROP TABLE test;

Query OK, 0 rows affected (0.01 sec)

mysql> CREATE TABLE test
(
id INT,
NAME VARCHAR(10)
);
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO test VALUES(1,'a1'),(2,'a2'),(3,'a3'),(4,'a4'),(1,'a1');
Query OK, 5 rows affected (0.00 sec)
Records: 5 Duplicates: 0 Warnings: 0

mysql> SELECT * FROM test;
+------+------+
| id | NAME |
+------+------+
| 1 | a1 |
| 2 | a2 |
| 3 | a3 |
| 4 | a4 |
| 1 | a1 |
+------+------+
5 rows in set (0.00 sec)

mysql> ALTER IGNORE TABLE test ADD UNIQUE INDEX idx_id_name (id,NAME);
Query OK, 5 rows affected, 1 warning (0.02 sec)
Records: 5 Duplicates: 1 Warnings: 1

mysql> SHOW WARNINGS;
+---------+------+-----------------------------------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------------------------------+
| Warning | 1681 | 'IGNORE' is deprecated and will be removed in a future release. |
+---------+------+-----------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> SELECT * FROM test;
+------+------+
| id | NAME |
+------+------+
| 1 | a1 |
| 2 | a2 |
| 3 | a3 |
| 4 | a4 |
+------+------+
4 rows in set (0.00 sec)

 

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved