我有两张表employee
和employee_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中没有值。
我该怎么做?
答案 0 :(得分:3)
使用左连接(从employee表中检索行,无论他们是否在employee_salary中匹配):
select *
from employee a
left join employee_salary b
on a.empno = b.empno
where a.branch_id = '001';