我有两个表连接与左外连接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