SELECT bo.* FROM boys bo RIGHT OUTER JOIN beauty b ON b.`boyfriend_id`=bo.`id` WHERE b.`id`>3; #案例:查询哪个城市没有部门
SELECT city FROM locations l LEFT OUTER JOIN departments d ON l.`location_id`=d.`location_id` WHERE d.`department_id` IS NULL; #案例:查询部门名为SAL或IT的员工信息(用外连接,内连接有可能没有员工,查询不出来) #用外连接,因为可能有的部门名为上述,但没有员工,以null来填充员工表 #用内连接,只会匹配有员工的SAL或IT,会忽视掉外连接中主表有但从表没有的
SELECT e.*,d.`department_name` FROM departments d LEFT JOIN employees e ON d.`department_id`=e.`department_id` WHERE d.`department_name` IN ('SAL','IT');