MySQL 七种 JOIN
共有
SELECT * FROM t_dept a INNER JOIN t_emp b ON a.id = b.deptId;
左独占+共有
SELECT * FROM t_dept a LEFT JOIN t_emp b ON a.id = b.deptId;
右独占+共有
SELECT * FROM t_dept a RIGHT JOIN t_emp b ON a.id = b.deptId;
左独占
SELECT * FROM t_dept a LEFT JOIN t_emp b ON a.id = b.deptId WHERE b.deptId IS NULL;
右独占
SELECT * FROM t_dept a RIGHT JOIN t_emp b ON a.id = b.deptId WHERE a.id IS NULL;
左右全部
SELECT * FROM t_dept a LEFT JOIN t_emp b ON a.id = b.deptId UNION SELECT * FROM t_dept a RIGHT JOIN t_emp b ON a.id = b.deptId;
左独占+右独占
SELECT * FROM t_dept a LEFT JOIN t_emp b ON a.id = b.deptId WHERE b.deptId IS NULL UNION SELECT * FROM t_dept a RIGHT JOIN t_emp b ON a.id = b.deptId WHERE a.id IS NULL;
相关推荐
翡翠谷 2020-05-03
愿天下再无BUG 2020-04-24
wensonlee 2020-04-11
贤冰 2020-02-23
hevenue 2020-01-23
SuperYPC 2020-01-23
georgeandgeorge 2019-12-28
azhou 2019-11-03
敏敏张 2018-06-14
lixiaotaoplus 2017-04-24
赫赫小虾 2015-08-28
guohan 2012-11-01
阿尼古 2019-06-30
Lendor 2015-08-26
文报 2019-06-29
claytang 2013-07-30
nengyu 2013-07-03
Gbug00 2013-05-29