Eliminating Duplicates by Adding an Index
mysql>
mysql> CREATE TABLE mytbl
-> (
-> i INT,
-> c CHAR(1)
-> );
Query OK, 0 rows affected (0.01 sec)
mysql>
mysql>
mysql> INSERT INTO mytbl (i,c) VALUES(1,'a'),(1,'a'),(1,NULL),(1,NULL),(2,'a'),(2,'a'),(2,'b'),(2,'b');
Query OK, 8 rows affected (0.00 sec)
Records: 8 Duplicates: 0 Warnings: 0
mysql>
mysql>
mysql> SELECT * FROM mytbl;
+------+------+
| i | c |
+------+------+
| 1 | a |
| 1 | a |
| 1 | NULL |
| 1 | NULL |
| 2 | a |
| 2 | a |
| 2 | b |
| 2 | b |
+------+------+
8 rows in set (0.00 sec)
mysql>
mysql> drop table mytbl;
Query OK, 0 rows affected (0.00 sec)
Related examples in the same category