03MySQL3

一、内外连接全连接,左右连接

通过两张表查找其对应的记录.

隐式 内连接 select * from a,b where a.列名 = b.列名

#左连接

select * from a left outer join b on a.id = b.id

#右连接

select * from  a  right  outer  join  b  on  a.id = b.id

#全连接

可以使用union来达到全外连接的查询效果。

union :可以将左外连接查询和右外连接查询两条sql语句使用union合并起来进行查询,去掉重复的数据。

select * from a left outer join b on a.id = b.id

union

select * from a right outer join b on a.id = b.id

小结

内连接:

1、 隐式内连接:Select from a,b where a.id = b.id;结果:C2、 显示内连接:Select from a inner join b on a.id = b.id;结果:C 外连接:1、 左外连接select from a left outer join b on a.id = b.id结果:A+C2、 右外连接select from a right outer join b on a.id = b.id结果:B+C3、 union:相当于全外连接select from a left outer join b on a.id = b.idunionselect from a right outer join b on a.id = b.id 结果:A+B+C,会自动虑重 select from a left outer join b on a.id = b.idunion allselect from a right outer join b on a.id = b.id结果:A+B+C,有重复数据

Powered by Hexo and Hexo-theme-hiker

Copyright © 2016 - 2018 Francis的个人博客 All Rights Reserved.

UV : | PV :