Group by clause in Sql to find duplicate records

There are some situation when we have to find the duplicate records in a table. So to find the duplicate records we will use group by clause in sql.

Group by clause in SQL groups the result set according to the group by condition. We will group the result set by using group by clause and then count the no of records.
lets take an example

Select email,count(*) from students group by email having count(*) > 1

The above query will list all the duplicate records in the students table according to email. So if two students have same email id then that record will be listed in the result set.

Be the first to comment

Leave a Reply

Your email address will not be published.