即使数据存在于第二个表中,Oracle也会加入表并获取数据

时间:2015-10-20 07:06:38

标签: sql oracle

我有两张表employeeemployee_salary

select * from employee where branch_id = '001';

select * from employee_salary where branch_id = '001';

select *
from employee a,
     employee_salary b
where a.branch_id = '001' and a.empno = b.empno;

在第三个sql中,我需要从employee表中获取值,即使employee_salary中没有值。

我该怎么做?

1 个答案:

答案 0 :(得分:3)

使用左连接(从employee表中检索行,无论他们是否在employee_salary中匹配):

select *
from employee a
left join employee_salary b
on a.empno = b.empno
where a.branch_id = '001';