[英]if statement in where clause because of outer join
我想從表中選擇2個條件中的where子句的值。
select a.value1
b.value2
c.value3
from a,b,c
where
a.header_id = b.header_id
and b.line_id = c.line_id(+)
如果c.line_id不為null,則有更多where子句,例如
c.active = 'Y'
c.active_date > sysdate
有什么想法,如何使這種說法行得通?
使該語句起作用的最好方法是使用ANSI連接重寫它:
SELECT
a.value1
, b.value2
, c.value3
FROM a
JOIN b ON a.header_id = b.header_id
LEFT OUTER JOIN c ON b.line_id = c.line_id
現在毫無疑問,附加條件的位置-由於它僅適用於c
不為null的行,因此可以將其添加到ON
子句中:
SELECT
a.value1
, b.value2
, c.value3
FROM a
JOIN b ON a.header_id = b.header_id
LEFT OUTER JOIN c ON b.line_id = c.line_id
AND c.active = 'Y'
AND c.active_date > sysdate
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.