如何连接3个左外连接的表?我能够做table1和table2之间的左外连接,但不能table3。ORACLE SQL:无法左连接3个表
我尝试了以下,但不知道如何加入table3。
select tab1.id, tab2.status, tab3.job_history
from table1 tab1
left outer join table2 tab2 on tab1.id=tab2.id
where tab1.job_title='accounting'
我的表架构是:
table 1:
id number(5) primary key,
status_code number(5),
job_title varchar2(20)
name varchar2(30)
table 2:
status_code number(5) primary key,
status varchar2(15)
table 3:
id number(5)
job_history varchar2(20)
条件:
table1.status_code
可以null
table1.id
可能没有任何匹配table3.id
我想找到一个具有table1.job_title = 'accounting'
table1中的记录或表3中具有table3.job_history = 'accounting'
时table1.id = table3.id
并同时获得与table1.status_code = table2.status_code
您显示的模式没有'table 2 id',那么你想要执行什么'left outer join'? (你的SQL在tab1.id = tab2.id中显示'table2 tab2',但没有table2 ID列。) – 2013-03-24 20:44:17
表1和表3之间的关系是一对多关系吗? – mickfold 2013-03-24 20:56:08