如何通过其他表的唯一值仅选择id

时间:2018-04-25 20:15:21

标签: mysql sql

我有一张桌子customers。如何仅为电子邮件列中的不同值选择ID?

+----+------------------+
| Id | Email            |
+----+------------------+
| 1  | sergiy@gmail.com |
| 2  | bob@gmail.com    |
| 3  | anre@gmail.com   |
| 4  | sergiy@gmail.com |
| 5  | antony@gmail.com |
+----+------------------+

结果将是:

[1,2,3,5]

到目前为止,我已经尝试过了:

select distinct id, email from customers group by id;

1 个答案:

答案 0 :(得分:3)

select min(id) from Customers group by email;