SQL中join的用法解析(inner join、full out join、left join)

版权声明:本文为CSDN博主「」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。

原文链接:https://blog.csdn.net/Megustas_JJC/article/details/86092980

对于各种join情况的总结图:

SQL中join的用法解析(inner join、full out join、left join)

例如有如下关系的数据:

SQL中join的用法解析(inner join、full out join、left join)

1、inner join

 SQL中join的用法解析(inner join、full out join、left join)

select * from Table_a
join Table_b on Table_a.id_a = Table_b.id_b

 SQL中join的用法解析(inner join、full out join、left join)

2.1、full outer join等于full join

 SQL中join的用法解析(inner join、full out join、left join)

select * from Table_a
full join Table_b
on Table_a.id_a = Table_b.id_b

SQL中join的用法解析(inner join、full out join、left join)

2.2、full outer join but a.Key is null or b.Key is null

 SQL中join的用法解析(inner join、full out join、left join)

select * from Table_a
full outer join Table_b
on Table_a.id_a = Table_b.id_b
where Table_a.id_a is null or Table_b.id_b is null

SQL中join的用法解析(inner join、full out join、left join)

3.1、left outer join等于left join

 SQL中join的用法解析(inner join、full out join、left join)

select * from Table_a
left join Table_b on Table_a.id_a = Table_b.id_b

 SQL中join的用法解析(inner join、full out join、left join)

3.2、left outer join but b.Key is null

 SQL中join的用法解析(inner join、full out join、left join)

select * from Table_a

left outer join Table_b on Table_a.id_a = Table_b.id_b

where Table_b.id_b is null

 SQL中join的用法解析(inner join、full out join、left join)

笛卡尔积
select * from Table_a ,Table_b
SQL中join的用法解析(inner join、full out join、left join)

————————————————
版权声明:本文为CSDN博主「Megustas_JJC」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/Megustas_JJC/article/details/86092980

上一篇:Oracle左连接、右连接、全外连接以及(+)号用法


下一篇:《Java编程思想》读书笔记10.内部类