left join 和 right join 时,on 的关联条件只会对关联表的数据进行过滤,无法对主表的数据进行过滤,若想对主表的数据进行筛选,需要where里加条件进行筛选。
select *
from userInfo a
left join roleInfo b on a.userId = b.userId
where a.xxx = ''
--在这个SQL里面,如果想对a表的数据过滤,只能在where里面写条件
inner join时,on的关联条件会对主表和关联表起作用,可以没有where条件,就能筛选出同时满足关联条件的主表和关联表的数据。
select *
from userInfo a
inner join roleInfo b
on a.userId = b.userId
and a.xxx = ''
and b.xxx = ''
--只在on里面写条件也可以筛选出满足条件的数据