Selasa, 26 Oktober 2021

How to Find Duplicate values in SQL? GROUP BY and HAVING Query Example Tutorial

Hello guys, if you are wondering how to find duplicate values in a table then you can use the GROUP BY and HAVING clause in SQL. Using group by you can create groups and if your group has more than 1 element it means it's kind of duplicate. For example, you need to write a SQL query to find all duplicate emails in a table named Person. This is a popular SQL Query interview question as well as a Leetcode problem. You can see that email a@b.com is a duplicate email as it appears twice in the table. You need to write a query to find all duplicate values, I mean emails in this case. 

+----+---------+
| Id | Email   |
+----+---------+
| 1  | a@b.com |
| 2  | c@d.com |
| 3  | a@b.com |
+----+---------+

For example, your query should return the following for the above table:

+---------+
| Email   |
+---------+
| a@b.com |
+---------+

Note: All emails are in lowercase.

Lorem ipsum is simply dummy text of the printing and typesetting industry.

Comments


EmoticonEmoticon