让我们首先创建一个表-
mysql> create table DemoTable -> ( -> value int -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(10); mysql> insert into DemoTable values(100); mysql> insert into DemoTable values(20); mysql> insert into DemoTable values(10); mysql> insert into DemoTable values(30); mysql> insert into DemoTable values(40); mysql> insert into DemoTable values(20);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
这将产生以下输出-
+-------+ | value | +-------+ | 10 | | 100 | | 20 | | 10 | | 30 | | 40 | | 20 | +-------+ 7 rows in set (0.00 sec)
以下是查找重复值并显示一次的查询-
mysql> select *from DemoTable group by value having count(*) > 1;
输出结果
这将产生以下输出-
+-------+ | value | +-------+ | 10 | | 20 | +-------+ 2 rows in set (0.00 sec)