Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return count of duplicate values in a column? (SQL)

I want a query to count the duplicate values in a column, e.g.,

total records=SELECT COUNT(column_name) FROM table_name;
distinct records=SELECT COUNT(DISTINCT column_name) FROM table_name;
duplicate count=total records-distinct records;
like image 560
Rajasekhar Avatar asked Oct 31 '25 05:10

Rajasekhar


1 Answers

A simplification of the SQL you provided:

    SELECT Count(Column) - Count(DISTINCT Column)
    FROM   yourTable
like image 151
Deep Avatar answered Nov 01 '25 19:11

Deep



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!