
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Count Duplicate Values from a Single Column in MySQL
Let us first create a table −
mysql> create table DemoTable -> ( -> Number int -> ); Query OK, 0 rows affected (0.83 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.47 sec) mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.15 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+--------+ | Number | +--------+ | 20 | | 20 | | 10 | | 30 | | 10 | | 10 | +--------+ 6 rows in set (0.00 sec)
Following is the query to select count values from a single column −
mysql> select Number,count(*) from DemoTable group by Number;
This will produce the following output −
+--------+----------+ | Number | count(*) | +--------+----------+ | 20 | 2 | | 10 | 3 | | 30 | 1 | +--------+----------+ 3 rows in set (0.00 sec)
Advertisements