您的位置:首页 > 数据库

Remove Duplicates from Table

2016-04-07 19:29 567 查看


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  | a@gmail.com |
| 2  | b@gmail.com |
| 3  | a@gmail.com |
| 4  | b@gmail.com |
+----+-------------+

Does deleting duplicate email records mean deleting all duplicates except the first entry?
+----+-------------+
| 1  | a@gmail.com |
| 2  | b@gmail.com |
+----+-------------+

Or we don't care if the deleted entry is not the first one, such as this is correct too?
+----+-------------+
| 3  | a@gmail.com |
| 4  | b@gmail.com |
+----+-------------+




内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  数据库