left join on 后and 和 where 的区别

Posted on 2017-05-05 17:41  冠军33  阅读(21571)  评论(3编辑  收藏  举报

SELECT * FROM student a LEFT JOIN sc b ON a.Sid = b.Sid AND a.Sname="赵雷"

结果:(left join 左连接,左表所有数据 拼接 右表符合on条件的数据。on后用and连接,‘a.Sid = b.Sid AND a.Sname="赵雷"’都作为on条件)


SELECT * FROM student a LEFT JOIN sc b ON a.Sid = b.Sid WHERE a.Sname="赵雷"

结果:(当on后用where连接,where作为筛选条件,筛选‘student a LEFT JOIN sc b ON a.Sid = b.Sid’的结果集)

 

Copyright © 2024 冠军33
Powered by .NET 9.0 on Kubernetes