zoukankan      html  css  js  c++  java
  • sql两表连接查询(转)

    例子:  
      a表       id   name     b表     id     job   parent_id  
                  1   张3                   1     23     1  
                  2   李四                  2     34     2  
                  3   王武                  3     34     4  
       
      a.id同parent_id   存在关系   
        
      内连接   
      select   a.*,b.*   from   a   inner   join   b     on   a.id=b.parent_id  
       
      结果是    
      1   张3                   1     23     1  
      2   李四                  2     34     2   
        
      左连接   
      select   a.*,b.*   from   a   left   join   b     on   a.id=b.parent_id  
       
      结果是    
      1   张3                    1     23     1  
      2   李四                  2     34     2  
      3   王武                  null   

      右连接   
      select   a.*,b.*   from   a   right   join   b     on   a.id=b.parent_id  
       
      结果是    
      1   张3                   1     23     1  
      2   李四                 2     34     2  
      null                       3     34     4   
        
      完全连接   
      select   a.*,b.*   from   a   full   join   b     on   a.id=b.parent_id   

      结果是    
      1   张3                   1     23     1  
      2   李四                 2     34     2  
      null                 3     34     4  
      3   王武                 null

  • 相关阅读:
    11111 Generalized Matrioshkas
    Uva 442 Matrix Chain Multiplication
    Uva 10815 Andy's First Dictionary
    Uva 537 Artificial Intelligence?
    Uva 340 MasterMind Hints
    SCAU 9508 诸葛给我牌(水泥题)
    Uva 10420 List of Conquests(排序水题)
    Uva 409 Excuses, Excuses!
    10/26
    11/2
  • 原文地址:https://www.cnblogs.com/yangwujun/p/2801907.html
Copyright © 2011-2022 走看看