left join 与 right join 以及 inner join 的区别
step1:在数据库建立两张表A,B
step2:给两张表添加数据
step3:测试join的写法
select * from A a join B b on a.id=b.id;
select * from A a inner join B b on a.id=b.id
测试发现 join与Inner join的结果是一样的,等值连接,只返回表中字段相等的行
step4:测试左外连接
select * from A a left outer B b on a.id=b.id
select * from A a left B b on a.id=b.id
经过测试发现,left join 与 left outer join 是等效的,返回包括左表中的所有记录和右表中联结字段相等的记录
step4:测试右连接 与右外连接
select * from A a right outer join B b on a.id=b.id
select * from A a right join B b on a.id=b.id
经过测试发现 right outer join 与right join 是等效的,返回包括右表中的所有记录和左表中联结字段相等的记录
step5:全连接
经过测试,发现MySQL不支持全连接,上网查询资料发现MySQL的全连接只能通过Union关键字来实现
select * from A a left join B b on a.id=b.id
union
select * from A a right join B b on a.id=b.id