Remove Duplicates from Table

Remove Duplicates from Table

[Description]
You are give a table named Person

Code:   Select all
[Description]
You are give a table named Person

Code: Select all
+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| email       | varchar |
| id          | int     |
+-------------+---------+

id is the primary key column for this table.

Write a SQL to delete all the duplicated email records

id is the primary key column for this table.

Write a SQL to delete all the duplicated email records

For example, if the rows are:

For example, if the rows are:
+----+-------------+
| 1  | [email protected] |
| 2  | [email protected] |
| 3  | [email protected] |
| 4  | [email protected] |
+----+-------------+

Does deleting duplicate email records mean deleting all duplicates except the first entry?
+----+-------------+
| 1  | [email protected] |
| 2  | [email protected] |
+----+-------------+

Or we don't care if the deleted entry is not the first one, such as this is correct too?
+----+-------------+
| 3  | [email protected] |
| 4  | [email protected] |
+----+-------------+

Remove Duplicates from Table_第1张图片

Remove Duplicates from Table_第2张图片

你可能感兴趣的:(数据库)