我们可以使用COUNT(*)和GROUP BY子句来找出列中值的重复。以下是示例,使用表“ Student”的“名称”列上的COUNT(*)和GROUP BY子句进行演示-
mysql> select count(*),name from student group by name; +----------+---------+ | count(*) | name | +----------+---------+ | 1 | Aarav | | 2 | Gaurav | | 1 | Harshit | +----------+---------+ 3 rows in set (0.00 sec)
上面查询的结果集显示该值在该列中重复了多少次。在上面的示例中,“ Gaurav”在“名称”列中重复了两次。可以从下面的“ SELECT *” 查询中验证相同内容-
mysql> Select * from Student; +------+---------+---------+-----------+ | Id | Name | Address | Subject | +------+---------+---------+-----------+ | 1 | Gaurav | Delhi | Computers | | 2 | Aarav | Mumbai | History | | 15 | Harshit | Delhi | Commerce | | 20 | Gaurav | Jaipur | Computers | +------+---------+---------+-----------+ 4 rows in set (0.00 sec)