Start networking and exchanging professional insights

Register now or log in to join your professional community.

Follow

Do you know how to count duplicate values in sql ?

user-image
Question added by mohamed khiry , Senior Database Administrator , confidential
Date Posted: 2016/09/27
Souleimane BELARIBI
by Souleimane BELARIBI , BigData / Business Intelligence Consultant Intern , Necker Enfants Malades Hospital

SELECT name, email, COUNT(*)FROM users GROUPBY name, email HAVING COUNT(*)>1

Morteza Nemati
by Morteza Nemati , Coe & Founder , Ravin Data Process

for count douplicate value in sql can use Group By and Having...

SELECT FIELD, COUNT(FIELD) FROM TABLE GROUP BY FIELD HAVING COUNT(FIELD)>1;

Rezeq Tawfiq Abdel Hafez Abu Rezeq
by Rezeq Tawfiq Abdel Hafez Abu Rezeq , System Administartor , IBM - Contractor

select column_name,count(column_name) from Table_namehaving count(column_name) > 1group by column_name

khalid Hassanien
by khalid Hassanien , Financial Manger , Alrwania Ltd

If you have a column with duplicated values, and you want to know what are those duplicated values are and how many duplicates are there for each of those values, you can use the "GROUP BY ... HAVING" clause.

To count all the duplicate records in a column of the table use this code:

SELECT Column_name, COUNT(*) Count_Duplicate FROM Table_name GROUP BY Column_name HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC

To count all the duplicate records in two columns of the table:

SELECT Column1, Column2, COUNT(*) Count_Duplicate FROM Table_name GROUP BY Column1, Column2 HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC

To count all the duplicate records in all columns of the table:

SELECT , COUNT(*) Count_Duplicate FROM Table_name GROUP BY HAVING COUNT(*) > 1 ORDER BY COUNT(*) DESC

Falak Shaer
by Falak Shaer , Project Coordinator , Bader H Al-Hussini Sons & Co.

SELECT name, email, COUNT(value) 

FROM users 

GROUP BY name, email

HAVING COUNT(value) > 1

Riadh ZRIBI
by Riadh ZRIBI , Responsable du système d'information , SIMOP-Tunisie

Using group by  . exemple :

 

Select product_code, product_name , count(*) from product 

group by product_code, product_name  

having count(*) > 1

 

Here we want to know which products found in the result more than one time .

Jay Nagar
by Jay Nagar , Database Administrator , Universal Software

SELECT COLUMN_NAME,COUNT(COLUMN_NAME) GROUP BY COLUMN_NAME HAVING COUNT(*)>1

Enas  Fares
by Enas Fares , Syria , Syriatel

select *

form tables,

Group by coulmnName,

having count(*)>1;

Sajid Z Saiyed
by Sajid Z Saiyed , Senior Software Engineer - Team Leader , Emirates Airline

below query to find duplicate for given columns

SELECT name, email, COUNT(*)FROM users GROUPBY name,email HAVING COUNT(*)>1 

Mathew Joseph
by Mathew Joseph , Architect , WIPRO

Use count(*)  group by on the column you want to find duplicates and then filter count(*) >1

More Questions Like This

Do you need help in adding the right keywords to your CV? Let our CV writing experts help you.