Will list rows where left and right match
select
emp.id,
emp.name,
dept.name
from employee emp
inner join department dept
on emp.dept_id = dept.dept_id
Will list only those employees who have a department which is found in the dept table.
July 19, 2017
Right Join
Every rows from right table and matching records from left
select
emp.id,
emp.name,
dept.name
from employee emp
right join department dept
on emp.dept_id = dept.dept_id
Even if the department doesn't have employees, it will be listed. If an employee doesn't have a department, it will not be listed.
select
emp.id,
emp.name,
dept.name
from employee emp
right join department dept
on emp.dept_id = dept.dept_id
Even if the department doesn't have employees, it will be listed. If an employee doesn't have a department, it will not be listed.
Left Join
Every rows from left table and matching records from right
select
emp.id,
emp.name,
dept.name
from employee emp
left join department dept
on emp.dept_id = dept.dept_id
Even if the employee doesn't have a department, he/she will be listed here.
select
emp.id,
emp.name,
dept.name
from employee emp
left join department dept
on emp.dept_id = dept.dept_id
Even if the employee doesn't have a department, he/she will be listed here.
Subscribe to:
Posts (Atom)