select e.emp_no,e.birth_date,d.dept_no,n.dept_name
from employees e
left join (dept_emp d,departments n)
on e.emp_no=d.emp_no and d.dept_no=n.dept_no
order by emp_no;
RIGHT LEFT-将dept_emp和departments的数据合并展示,且部门表departments信息为必展示项。
select * from dept_emp d
right join departments n
on d.dept_no=n.dept_no
order by emp_no;
FULL JOIN-将dept_emp表和departments表的行全部合并返回
注:因为 MySQL 不支持 full join,所以想要实现此功能需要使用 left join union right join 的方法:
select * from dept_emp d
left JOIN departments n
on d.dept_no=n.dept_no
union
select * from dept_emp d
right join departments n
on d.dept_no=n.dept_no
order by emp_no limit 100;