SQL的七种连接
book表:

t_book表:
一:inner join AB共有的。

1 select * from book 2 inner join t_book 3 on book.t_id=t_book.t_id
查询结果:

二:left join A表的所有,B表没有的用null

select * from book
left join t_book
on book.t_id=t_book.t_id
输出结果:

三:RIGHT JOIN B表的所有,A表没有的用Null

1 select * from book 2 right join t_book 3 on book.t_id=t_book.t_id
输出结果:

四:left join where b.id is not null

select * from book left join t_book on book.t_id=t_book.t_id where t_book.t_id is not null ;

五:right join where a.id is not null

select * from book right join t_book on book.t_id=t_book.t_id where book.t_id is not null ;
六:full outer join

七:full outer join where b.id is not null

第六和第七MySQL没有这种写法
八:笛卡尔集 两个表相乘。
select * from book,t_book




浙公网安备 33010602011771号