表一 user(用户表)
image.png
表二 dept(部门表)
image.png
外连接
image.png

select * from user u left join dept d on u.dept = d.id where d.id is null;

image.png
左外连接
image.png

select * from user u left join dept d on u.dept = d.id;

image.png
全连接
image.png

    -- 左独有数据
select * from user u left join dept d on u.dept = d.id where d.id is null
union
    -- 右独有数据
select * from user u right join dept d on u.dept = d.id where  u.id is null;

image.png
全外连接
image.png

    -- 左外
select * from user u left join dept d on u.dept = d.id
union
    -- 右外
select * from user u right join dept d on u.dept = d.id;

image.png


爱看球的黄豆
1 声望0 粉丝