设为首页收藏本站
查看: 74|回复: 0

[PHP] mysql如何快速删除重复的数据_MySQL

[复制链接]

论坛元老

Rank: 6Rank: 6

积分
34274
主题
17031
UID
1347
M币
67
贡献
17176

  • 发表于 2017-5-12 16:11:00 | 显示全部楼层 |阅读模式
    在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)
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    在我站开通SVIP可同时获得17个站点VIP资源 立即登录 立即注册
    快速回复 返回顶部 返回列表