SQL的4种连接

数据表的连接有:

1、内连接(inner join): 只连接匹配的行。

 

2、外连接(outer join): 包括  左外连接(left outer join)、右外连接(right outer join)和全外连接(full outer join)

(1) 左外连接 left outer join 或者 左连接   从左表 (table_name1) 那里返回所有的行,即使在右表 (table_name2) 中没有匹配的行。

select * from book as a left join stu as b on a.sutid = b.stuid

 

(2) 右外连接 right outer join 或者 右连接   右表 (table_name2) 那里返回所有的行,即使在左表 (table_name1) 中没有匹配的行。

 

select * from book as a right join stu as b on a.sutid = b.stuid

(3)全外连接 full outer join 或者 全连接  查询出左表和右表的所有数据,但是去除两表的重复数据。

原文地址:https://www.cnblogs.com/tianpin/p/10432535.html