select a.id, a.salary ,b.id, b.salary
from a
left join b
on a.id =b.id -- and b.salary != 200 ; -- 16s
where b.salary != 200 ;
主表中的条件要放到 where 条件中,
附表中的条件放到on 条件中.
附表中如果放到where条件中会把主表字段给过滤掉.
create table a ( id string , salary decimal(10,0) ) ;
insert into a values ( '1', 100) ;
insert into a values ( '10', 200) ;
insert into a values ( '20', 300) ;
create table b ( id string , salary decimal(10,0) ) ;
insert into b values ( '1', 100) ;
insert into b values ( '10', 200) ;
insert into b values ( '20', 300) ;
select a.id, a.salary ,b.id, b.salary from a inner join b on a.id =b.id -- and b.salary != 200 ; -- 16swhere b.salary != 200 ; #主表一定要放在where 条件中,