我有兩個表連接與左外連接Oracle查詢設計
員工
Employeed_Id Employee_Name Location_id
1 David 1
2 Andrew 2
3 Mike 3
4 steve 4
Employee_profile
profile_id profile_name location_id profile_location
1 manager 1 NYC
2 accountant 2 Jersey
3 engineer 1 Mexico
4 trainer 3 Boston
這是常見的查詢我要取回所有員工基於location.here profile_location是唯一的。
問題是,在應用程序的某些部分profile_location不是必需的。所以不需要上述表之間的外連接。
如何開發一個查詢,所以它應該正常運行,以防profile_location沒有外連接的輸入值。
下面是我的查詢:
select e.Employee_Name
from Employee e,
Employee_profile ep
where e.location_id (+) = ep.location_id
and ep.profile_location='xxxxx'
請不要使用隱式的連接在where子句。改用明確的'LEFT JOIN'。 –
@a_horse_with_no_name - 請不要關於ANSI加入。它們很酷,但會導致Oracle優化器出現問題。 – APC
你能澄清你的問題嗎?你是否想返回等於'profile_location'的記錄,但是如果該值不存在則返回記錄? – Taryn