[LeetCode] 182.Duplicate EmailsWrite a SQL query to find all duplicate emails in a table named Person.
For example, your query should return the following for the above table:
Note : All emails are in lowercase. This question asks us to find duplicate email addresses, so the most direct way is to use the fixed combination of Group by...Having Count(*)..., the code is as follows: Solution 1: SELECT Email FROM Person GROUP BY Email HAVING COUNT(*) > 1; We can also use internal intersection to do this, using Email to internally intersect the two tables, and then return rows with different IDs, which means that two different people use the same email address: Solution 2: SELECT DISTINCT p1.Email FROM Person p1 JOIN Person p2 ON p1.Email = p2.Email WHERE p1.Id <> p2.Id; References: https://leetcode.com/discuss/53206/a-solution-using-a-group-by-and-another-one-using-a-self-join This is the end of this article about SQL implementation of LeetCode (182. Duplicate mailboxes). For more relevant SQL implementation of duplicate mailboxes, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: CSS setting div background image implementation code
>>: Example of using #include file in html
1. Error reproduction I can access the MySQL data...
Nginx (engine x) is a high-performance HTTP and r...
Table of contents Background 1. What is dns-prefe...
What is a stored procedure Simply put, it is a se...
The first time I installed MySQL on my virtual ma...
When we want to use a new CSS feature, we always ...
Phenomenon The system could compile the Linux sys...
As a commonly used database, MySQL requires a lot...
The previous article on Docker mentioned the cons...
In Ubuntu, you often encounter the situation wher...
For example, when you create a new table or updat...
1. Changes in MySQL's default storage engine ...
This article mainly introduces the sample code of...
Here is an example code for using regular express...
MySQL error: Error code: 1293 Incorrect table def...