ON
1.只能用于连接 查询(内 外 交叉)
select* from test on id = 1;//报错,不能在普通查询里使用on,需要使用where
2.连接查询会产生一张中间表(临时表),ON是在生成中间表时使用的条件
3.先筛选出为表中的数据 再和事实表JOIN
4.会带出所有的数据,没有匹配上的用NULL填充
test1表:
test2表:
select* from test1 left join test2 on test1.id = test2.id and test1.id = 1
结果
WHERE
where是在中间表生成后对中间表进行过滤使用的条件
就是先JOIN后筛选
select* from test1 left join test2 on test1.id = test2.id where test1.id = 1;
结果
注:
1.外连接必须使用ON
2.内连接 交叉连接单独使用ON和WHERE没有区别