mysql如何快速重複資料刪除的資料,mysql重複資料

來源:互聯網
上載者:User

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)

著作權聲明:本文為博主原創文章,未經博主允許不得轉載。

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.