We can use COUNT(*) and GROUP BY clause to find duplicates of a value in a column. The following is an example of using COUNT(*) and GROUP BY clause on the "Name" column of the "Student" table to demonstrate -
mysql> select count(*),name from student group by name; +----------+---------+ | count(*) | name | +----------+---------+ | 1 | Aarav | | 2 | Gaurav | | 1 | Harshit | +----------+---------+ 3 rows in set (0.00 sec)
The result set of the above query shows which value is repeated how many times in the column Second-rate. In the above example, "Gaurav" is repeated twice in the "name" column. The same can be verified from the ‘SELECT *’ query below -
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)
The above is the detailed content of How to know the number of repetitions of a value in a column with the help of grouping function COUNT(*) and GROUP BY clause?. For more information, please follow other related articles on the PHP Chinese website!