外连接:内连接结果 主表中有而从表没有的结果
左外连接:left join 左边的是主表
右外连接:right join 右边的是主表
#案例:查询男朋友不在男神表的女神名
#左连接
SELECT
b.name
FROM
beauty b
LEFT OUTER JOIN
boys bo
ON
b.boyfriend_id=bo.id
WHERE
bo.`id` IS NULL;
#右连接
SELECT
b.name
FROM
boys bo
RIGHT OUTER JOIN
beauty b
ON
b.`boyfriend_id`=bo.`id`
WHERE
bo.id IS NULL;
#案例:查询哪个部门没有员工
SELECT
d.department_name
FROM
employees e
RIGHT OUTER JOIN
departments d
ON
e.`department_id`=d.`department_id`
WHERE
e.`department_id` IS NULL;