Reputation: 3092
I have two tables employee
and 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;
In the third sql, I need to fetch the values from employee table, even if there are no values in employee_salary.
How can I do this?
Upvotes: 0
Views: 39
Reputation: 2617
Use a left join (retrieves rows from employee table regardless if they have a match in employee_salary or not):
select *
from employee a
left join employee_salary b
on a.empno = b.empno
where a.branch_id = '001';
Upvotes: 3