sql 中on和where的区别

1 inner join 时查询出来的结果相同

 select 
a.id as channel_id,
a.channel_name, 
b.op_month,
b.living_count  as living_count,
 b.working_count  as working_count
from 
channel_info a
inner join 
st_people_mm b
ON
         cast(a.id as text) = b.channel_id
                where 
a.parent_channel_id = 465201548
and a.show_type = 'V'
     and  b.op_month = 201707

2 在使用left jion时,on和where条件的区别如下:

1、 on条件是在生成临时表时使用的条件,它不管on中的条件是否为真,都会返回左边表中的记录。

2、where条件是在临时表生成好后,再对临时表进行过滤的条件。这时已经没有left join的含义(必须返回左边表的记录)了,条件不为真的就全部过滤掉。

猜你喜欢

转载自blog.csdn.net/zhilinboke/article/details/80775875
今日推荐