只是不选择mysql的重复值?

时间:2017-12-05 10:43:41

标签: mysql database

我正在寻找一种运行简单SELECT语句的方法。我有一个表有两列:id和email。

我想运行一个不会返回重复值的SELECT语句。例如,请采用以下数据:

1   example@hotmail.com  
2   example12@hotmail.com  
3   example@hotmail.com 
4   example@hotmail.com

我希望它只返回以下内容:

2   example12@hotmail.com

2 个答案:

答案 0 :(得分:2)

使用聚合count(*)并使用having子句检查聚合函数的结果,以过滤掉那些不重复的记录

select *
from demo
group by email
having count(*) = 1

Demo

答案 1 :(得分:0)

通过电子邮件从表组中选择id,电子邮件,其中包含count(*)= 1;