如何将 oracle 外连接与过滤器 where 子句一起使用 [英] How to use oracle outer join with a filter where clause
本文介绍了如何将 oracle 外连接与过滤器 where 子句一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我写一个sql:
select *
from a,b
where a.id=b.id(+)
and b.val="test"
并且我想要 a 中的所有记录,其中 b 中的相应记录不存在或存在 val="test",这是正确的查询吗?
and i want all records from a where corresponding record in b does not exist or it exists with val="test", is this the correct query?
推荐答案
最好使用 ANSI 语法
You're much better off using the ANSI syntax
SELECT *
FROM a
LEFT OUTER JOIN b ON( a.id = b.id and
b.val = 'test' )
你也可以使用 Oracle 的语法做同样的事情,但它有点麻烦
You can do the same thing using Oracle's syntax as well but it gets a bit hinkey
SELECT *
FROM a,
b
WHERE a.id = b.id(+)
AND b.val(+) = 'test'
请注意,在这两种情况下,我都忽略了 c
表,因为您没有指定连接条件.而且我假设您真的不想将 A 连接到 B,然后用 C 生成笛卡尔积.
Note that in both cases, I'm ignoring the c
table since you don't specify a join condition. And I'm assuming that you don't really want to join A to B and then generate a Cartesian product with C.
这篇关于如何将 oracle 外连接与过滤器 where 子句一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文