【发布时间】:2014-01-02 09:54:29
【问题描述】:
我有两个表和一个如下所示的查询::
select * from table_1
where x.column_1 in (
select column_2 from table_2
where column_3 = 'foo')
这几乎对我有用; column_1 和 column_2 中有空值,我希望将其视为匹配项。
我可以用这个写一个union:
-- query above
union all
select * from table_1
where column_2 is null
and exists (select * from table_2
where column_3 = 'foo'
and column_2 is null)
但是会扫描每个表两次,这似乎效率低下。
有没有办法将这两个查询结合起来进行高效查询?
【问题讨论】:
-
哪个 RDBMS,任何或特定实例?