虾米窝窝 -- » MySQL:去掉表中重复记录
Subscribe RSS
MySQL:去掉表中重复记录 10月 29

Create Table: CREATE TABLE `users_groups` (
  `uid` int(11) NOT NULL,
  `gid` int(11) NOT NULL
) ENGINE=InnoDB
1 row in set (0.00 sec)

users_groups.txt内容:
11,502
107,502
100,503
110,501
112,501
104,502
100,502
100,501
102,501
104,502
100,502
100,501
102,501
110,501
mysql> load data infile ‘c:\\users_groups.txt’ into table users_groups fields
rminated by ‘,’ lines terminated by ‘\n’;
Query OK, 14 rows affected (0.05 sec)
Records: 14  Deleted: 0  Skipped: 0  Warnings: 0

mysql> select * from users_groups;
+—–+—–+
| uid | gid |
+—–+—–+
|  11 | 502 |
| 107 | 502 |
| 100 | 503 |
| 110 | 501 |
| 112 | 501 |
| 104 | 502 |
| 100 | 502 |
| 100 | 501 |
| 102 | 501 |
| 104 | 502 |
| 100 | 502 |
| 100 | 501 |
| 102 | 501 |
| 110 | 501 |
+—–+—–+
14 rows in set (0.00 sec)

mysql> create temporary table tmp_wrap select distinct * from users_groups;
Query OK, 9 rows affected (0.11 sec)
Records: 9  Duplicates: 0  Warnings: 0

mysql> truncate table users_groups;
Query OK, 14 rows affected (0.03 sec)

mysql> insert into users_groups select * from tmp_wrap;
Query OK, 9 rows affected (0.03 sec)
Records: 9  Duplicates: 0  Warnings: 0

mysql> select * from users_groups;
+—–+—–+
| uid | gid |
+—–+—–+
|  11 | 502 |
| 107 | 502 |
| 100 | 503 |
| 110 | 501 |
| 112 | 501 |
| 100 | 501 |
| 102 | 501 |
| 104 | 502 |
| 100 | 502 |
+—–+—–+
9 rows in set (0.02 sec)

mysql> drop table tmp_wrap;
Query OK, 0 rows affected (0.05 sec)

Category: PHP&MySQL  | 标签: , , ,  | 2176次阅读
你可以通过RSS 2.0来关注此文章的评论. 也可以留言或者从你的主页trackback.
1条留言
  1. Users_Groups 说到:

    Hubs of MySQL:去掉表中重复记录…

    hubs about Users_Groups to users_groups.txt内容: 11502 107502 100503 110501 112501 104502 100502 100501 102501 104502 100502 100501 102501 110501 mysql> load data infile ‘c:\\users_groups.txt’ into table users_groups fields rminated by ‘,…

留言

XHTML: 你可以使用以下的标签: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>