- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we know the repetition of a value in column with the help of group function COUNT(*) and GROUP BY clause?
We can use COUNT(*) and GROUP BY clause to find out the repetition of a value in the column. Following is the example, using COUNT(*) and GROUP BY clause on ‘Name’ column of table ‘Student’, to demonstrate it −
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 above query shows that which value is repeated and for how much times in the column. In the above example, ‘Gaurav’ is repeated two times in the column ‘name’. 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)
Advertisements