1 基础表
创建表A 表B
create table testA(id int, name varchar(10));
create table testB(id int, name varchar(10));
2 插入数据
insert into testA values(1,'zhangssa'),(2,'lisi'),(3,'wangwu')
insert into testB values(2,'zhangssa2'),(3,'lisi2'),(4,'wangwu4')
3 left join
3.1 当条件是 1 = 1 时,执行结果和outer join没有区别
select * from testA left join testB on 1 = 1;
3.2 当条件除了有 1 = 1之外,还有其他条件时,执行结果如下
其实这里有无 条件“1=1”,你都会发现没有区别
select A.* from testA left join B on 1 = 1 and testA.id = testB.id
select A.* from testA left join B on testA.id = testB.id