MySQL:去掉表中重复记录
2007-10-29 00:36Create 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)
Users_Groups:
2008-5-12 13:21:21
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 ‘,…