File tree Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Expand file tree Collapse file tree 1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Table: Person
3
+
4
+ +-------------+---------+
5
+ | Column Name | Type |
6
+ +-------------+---------+
7
+ | id | int |
8
+ | email | varchar |
9
+ +-------------+---------+
10
+ id is the primary key column for this table.
11
+ Each row of this table contains an email. The emails will not contain uppercase letters.
12
+
13
+
14
+ Required Query:
15
+
16
+ Report all the duplicate emails. Note that it's guaranteed that the email field is not NULL.
17
+
18
+
19
+ SQL Schema:
20
+
21
+ Create table If Not Exists Person (id int, email varchar(255))
22
+ Truncate table Person
23
+ insert into Person (id, email) values ('1', 'a@b.com')
24
+ insert into Person (id, email) values ('2', 'c@d.com')
25
+ insert into Person (id, email) values ('3', 'a@b.com')
26
+
27
+
28
+ Example:
29
+
30
+ Input:
31
+ Person table:
32
+ +----+---------+
33
+ | id | email |
34
+ +----+---------+
35
+ | 1 | a@b.com |
36
+ | 2 | c@d.com |
37
+ | 3 | a@b.com |
38
+ +----+---------+
39
+ Output:
40
+ +---------+
41
+ | Email |
42
+ +---------+
43
+ | a@b.com |
44
+ +---------+
45
+ */
46
+
47
+ -- Solution:
48
+ SELECT email
49
+ FROM Person
50
+ GROUP BY email
51
+ HAVING COUNT (email) > 1
You can’t perform that action at this time.
0 commit comments