Write a SQL query to find all duplicate emails in a table named Person.
+----+---------+
| 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 |
+---------+
+----+---------+
| 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.
这题用self join可以解决
# Write your MySQL query statement below
SELECT DISTINCT a.Email
FROM Person a JOIN Person b
ON(a.Email=b.Email and a.Id<>b.Id)
本文介绍了一种使用SQL自连接的方法来找出Person表中重复的电子邮件地址。通过一个具体的例子展示了如何构造查询语句,返回所有重复出现的电子邮件。
1138

被折叠的 条评论
为什么被折叠?



