mysql join详解

来源:互联网 发布:云数据分析 编辑:程序博客网 时间:2024/06/07 03:44
join等价于inner join内连接,是返回两个表中都有的符合条件的行。

left join左连接,是返回左表中所有的行及右表中符合条件的行。

right join右连接,是返回右表中所有的行及左表中符合条件的行。

full join全连接,是返回左表中所有的行及右表中所有的行,并按条件连接。

通常情况下,left join肯定比inner join返回的行数多。

为什么会多呢:

假设 a ,b 2个表

要查a的数据 b当做关联

select a.* from a left join b on a.id = b.aid where b.type=12

这是个左连接 当b表里多出一个type=12时数据不改变 

select a.* from a right  join b on a.id = b.aid where b.type=12

会多出一个type=12的数据 左边表的数据则用null填充 

inner join则会2者同时存在才会查出

原创粉丝点击