如何使用带有过滤条件where子句的oracle外连接 [英] How to use oracle outer join with a filter where clause
本文介绍了如何使用带有过滤条件where子句的oracle外连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我写一个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.
这篇关于如何使用带有过滤条件where子句的oracle外连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文