sql中on的连接条件与where的区别

left join [表名] on [条件]

where [条件]

--on表示连接条件

--where表示对结果的过滤条件

两者不尽相同,使用时需注意

例如:

select * from  table0 a left join table1 b on a.id = b.aid and b.status = 'Y' where a.status = 'Y' ---往往采用这种写法

select * from  table0 a left join table1 b on a.id = b.aid where a.status = 'Y' and b.status = 'Y' ---当连接不到b,b的所有属性为null时,达不到预期结果

猜你喜欢

转载自www.cnblogs.com/bevis-byf/p/10057954.html