a表 id name b表 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,b where a.id = b.id
select a.*,b.* from a inner join b on a.id=b.parent_id
结果是
1 张3 1 23 1
2 李四 2 34 2
2)左连接 : 左表的挨个信息去查询,查不到则将右边控制为null进行显示
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) 右连接 : 右表的挨个信息去查询,查不到则将左边控制为null进行显示
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
区分:
select * from a left join b on 条件1
select * from a left join b on 条件1 where 条件2 :相当于再次过滤