user2093576
user2093576

Reputation: 3092

Oracle join a table and fetch the data even if the data is present in second table

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

Answers (1)

Eduard Uta
Eduard Uta

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

Related Questions