Transmission Door
182. Duplicate Emailsmy SubmissionsQuestionTotal accepted:14498 Total submissions:38364 difficulty:easy
Write a SQL query to the Find all duplicate emails in a table named Person
.
+----+---------+| Id | Email |+----+---------+| 1 | [Email protected] | | 2 | [Email protected] | | 3 | [Email protected] |+----+---------+
For example, your query should return the following for the above table:
+---------+| Email |+---------+| [Email protected] |+---------+
Note:all emails is in lowercase.
Subscribe to see which companies asked this question
1 # Write Your MySQL query statement below 2 Select distinct from 3 4 where p1. Email=5and p1. Id!=P2. Id
About DISTINCT
SQL SELECT DISTINCT Statement
This chapter explains the SELECT DISTINCT statement.
SQL SELECT DISTINCT Statement
In the table, duplicate values may be included. That's not a problem, but sometimes you might want to just list different values (distinct).
Keyword DISTINCT is used to return only different values.
Grammar:
SELECT DISTINCT column name from table name
Using DISTINCT Keywords
If you want to pick all the values from the company column, we need to use the SELECT statement:
SELECT Company from Orders
"Orders" table:
| Company
OrderNumber |
Ibm |
3532 |
3wschool |
2356 |
Apple |
4698 |
3wschool |
6953 |
Results:
Company |
Ibm |
3wschool |
Apple |
3wschool |
Note that in the result set, 3wschool is listed two times.
To select only a different value from the company column, we need to use the Select DISTINCT statement:
DISTINCT
Results:
Company |
Ibm |
3wschool |
Apple |
Now, in the result set, "3wschool" is listed only once.
Leetcode 182. Duplicate Emails