`
avaj
  • 浏览: 234465 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

竟然不会Left join了

    博客分类:
  • DB
阅读更多

今天用到Left join 竟然将语法写错了......

 

select * from tt left join tt1 on tt.id=tt1.id 

id   name   id   name
--------------------------
1    a          1       a
2    b          2       b
3    c          3        c


select * from tt  left join tt1  on tt.id=tt1.id where tt.id=1

id   name   id   name
--------------------------
1    a          1       a

select * from tt  left join tt1 on tt.id=tt1.id and tt.id=1 

id   name   id   name
--------------------------
1      a       1      a    
2      b    NULL  NULL
3      c    NULL  NULL

--left join 以左边表为基础, 扫描右边表匹配的记录

select   *   from
table1   left   join   table2   on   条件1   
left   join   table3   on   条件2   
left   join   table4   on   条件3  
where   条件4
 
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics