mysql忽略任何不同的值

时间:2011-07-01 08:23:29

标签: mysql sql linux

我正在尝试运行一个不会显示不同/重复值的SQL查询。

例如,如果使用distinct选项,它只显示一个唯一的结果,但我想跳过所有检测到的不同值,即不显示不同的值

有可能吗?

    select col1  d from tb_col  where col1 = '123';

col1
------
123
123


(2 rows)


select distinct col1  d from tb_col  where col1 = '123';

col1
------
123
(1 row)

4 个答案:

答案 0 :(得分:6)

SELECT col1 
FROM tb_col 
GROUP BY col1 
HAVING count(*) = 1

答案 1 :(得分:5)

根本不显示重复项:

SELECT col1 AS d
FROM tb_col
GROUP BY col1
HAVING COUNT(*) = 1            --- or perhaps HAVING COUNT(*) > 1
                               --- it's not clear what you want.  

答案 2 :(得分:0)

  select col1
  from tb_col
  group by col1
  having count(*) < 2

答案 3 :(得分:-1)

尝试 DISTINCT 它会起作用!

SELECT DISTINCT(col1) as d from tb_col  where col1 = '123';