左连接显示左边全部的和右边与左边相同的 a.id = b.parent_id(+) left join 表名 on 右连接显示右边全部的和左边与右边相同的 a.id(+)= b.parent_id right join 表名 on 内连接是只显示满足条件的! inner join 表名 on 完全连接是显示两表的所有记录,不满足条件的以空显示! full join 表名 on
例子:
-------------------------------------------------
a表 b表
id name id job parent_id
1 张3 1 23 1
2 李四 2 34 2
3 王武 3 34 4
a.id同parent_id 存在关系
--------------------------------------------------
1) 内连接
select a.*,b.* from a inner join b on a.id=b.parent_id
结果是
1 张3 1 23 1
2 李四 2 34 2
2)左连接
select a.*,b.* from a left join b on a.id=b.parent_id
结果是
1 张3 1 23 1
2 李四 2 34 2
3 王武 null
3) 右连接
select a.*,b.* from a right join b on a.id=b.parent_id
结果是
1 张3 1 23 1
2 李四 2 34 2
null 3 34 4
4) 完全连接
select a.*,b.* from a full join b on a.id=b.parent_id
结果是
1 张3 1 23 1
2 李四 2 34 2
null 3 34 4
3 王武 null