1

where 和 on的区别

 

 



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 ; -- 16s where b.salary != 200 ; #主表一定要放在where 条件中,


LEFT JOIN 主表中的条件放在 where中.
附表 的条件放在 on 条件中.


 

posted @ 2024-12-29 19:59  萌哥-爱学习  阅读(11)  评论(0)    收藏  举报