Home >> MySql >> How to count duplicate rows in MySql

How to count duplicate rows in MySql

Department table:-   

dept_id     |  dept_name
    1           |    B.Tech
    1           |    B.Tech
    2           |    MBA
    2           |    MBA

SELECT col, COUNT(col) FROM table_name GROUP BY col HAVING COUNT(col) > 1;
 
SELECT dept_name, COUNT(dept_id) FROM department GROUP BY dept_id HAVING COUNT(dept_id)>1

Output

dept_name      |   count(dept_id)
    B.Tech         |         2
    MBA            |         2

Post Your Comment

Next Questions
How to count the number of duplicate entries a column
How To Find Duplicate Values
How to Find Duplicate Records
Count duplicates records
How to find duplicate records without GROUP BY
How can remove duplicate rows
how to Find average value of top n
How to calculate an average value across rows
How to get the average of the values
How to get the average of the last X values
How to Find a minimum value for a certain column value
How to select data where a field has a min value
Select row with min value in GROUP BY
Select Rows with min value for each group
How to Find a maximum value for a certain column value
How to select data where a field has a max value
Select row with max value in GROUP BY
Select Rows with max value for each group
How to find the sum of values in a column
How do you find the sum of all the values in a column
How to find absolute value of a column
How do I get the absolute value of a column
How to find round value
How to get rounded data
How to find square root of a number

Copyright ©2022 coderraj.com. All Rights Reserved.