SQL左右连接中的on and和on where的区别

SQL左右连接中的on and和on where的区别

左联时,ON后面的对左边表的条件对左边表数据无影响(因为左连接符合左边所有条件),但对右边表数据有影响,只有符合左边表条件时,右边表数据才会查出来
where 后面对两个表都有影响(影响全局的)

SELECT * FROM `user` us LEFT JOIN department de ON us.depart_id=de.id and us.depart_id='6'(on and 符合左边表所有条件,and后面无作用



SELECT * FROM `user` us LEFT JOIN department de ON us.depart_id=de.id where us.depart_id='6'(on where 对全部表有限制)

简单一句话:on and:符合左表所有条件,on where:对全部表有限制

原文地址:https://www.cnblogs.com/lidar/p/10523052.html