检查不存在的记录

时间:2016-11-03 08:20:57

标签: sql postgresql

我想选择条件为真或不存在的所有记录

我有类似的东西

select * 
  from trackings
 where field = 'domain' and string_value is null
    or *dont exist at all* -- <- Here is the troubled condition

处理此

的正确方法是什么

2 个答案:

答案 0 :(得分:1)

您在寻找exists吗?

select * from trackings
 where (field = 'domain' and string_value is null) or
        not exists (select 1 --TODO: put the right sql which should return an empty cursor
                      from trackings t
                     where t.field = 'domain' and 
                           t.string_value is null)

答案 1 :(得分:0)

SELECT * 
  FROM trackings
 WHERE (field = 'domain' 
   AND  string_value is null)
    OR (1 = 1)