多表连接查询
1、分为内连接和外连接
2、内连接
隐式内连接 where
显示内连接 inner join on
3、外连接
左外连接 left join on
右外连接right join on
4、隐式内连接 where
将两张表关联起来
select * from 表1 as 别名1,表2 as 别名2 where 连接条件(外键);
5、显示内连接 inner join on
将两张表关联起来
select * from 表1 as 别名1 inner join 表2 as 别名2 on 连接条件;
6、左外连接 left join on
将两张表关联起来
select * from 表1 as 别名1 left join 表2 as 别名2 on 连接条件;
以左表为主表,以右表为从表,将左表中的所有数据都会查询出来,右表不满足条件的使用null进行填充
7、右外连接 right join on
将两张表关联起来
select * from 表1 as 别名1 right join 表2 as 别名2 on 连接条件;
以右表为主表,以左表为从表,将主表中的所有数据都查询出来,从表不满足条件的使用null进行填充
8、可以通过条件左右表的位置来实现左右外连接的转换