连接数据库的四种方式

 时间:2026-04-23 02:10:40

1、 1) 内连接   


  select   a.*,b.*   from   a   inner   join   b     on   a.id=b.parent_id   

  或者是:

 select a.*,b.*  from a,b where a.id=b.parent_id

    


  结果是     
  1   张3                   1     23     1   
  2   李四                  2     34     2  

2、 2)左连接   


  select   a.*,b.*   from   a   left   join   b     on   a.id=b.parent_id       

  或者是

 select a.*,b.*  from a,b where a.id=b.parent_id(+)


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

3、 3) 右连接   


  select   a.*,b.*   from   a   right   join   b     on   a.id=b.parent_id  

  或者是

  select   a.*,b.*   from   a ,b  where   a.id(+)=b.parent_id  

     


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

4、 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
  • navicat怎么连接mysql
  • eclipse中java项目如何导入导出
  • 怎么用navicat向mysql表添加一行数据
  • 用word画E-R图,怎么画?
  • eclipse左侧项目栏不见了解决方法
  • 热门搜索
    手机空间不足怎么办 映众显卡怎么样 微博怎么认证 北京林业大学怎么样 cad怎么画角度 电脑忘记密码怎么办 河北美术学院怎么样 水草怎么养 怎么挖墙脚 东北林业大学怎么样