zoukankan      html  css  js  c++  java
  • sql之left join、right join、inner join的区别

    left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录 
    right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
    inner join(等值连接) 只返回两个表中联结字段相等的行

    有下面两张表

    表一:formone

    表二 :formtwo

    1.left join

     返回包括左表中的所有记录和右表中联结字段相等的记录 

    select * from formone fo left join formtwo ft on fo.id = ft.id;

    select * from formone fo ,formtwo ft where fo.id = ft.id(+);

    得到的结果是:

    2.right join

    返回包括右表中的所有记录和左表中联结字段相等的记录

    select * from formone fo right join formtwo ft on fo.id = ft.id;

    select * from formone fo ,formtwo ft where fo.id(+) = ft.id;

    得到的结果是:

    3.inner join

    只返回两个表中联结字段相等的行

    select * from formone fo inner join formtwo ft on fo.id = ft.id;

    select * from formone fo ,formtwo ft where fo.id = ft.id;

    得到的结果是:

  • 相关阅读:
    异常处理
    组合,封装
    自我介绍
    27python更多实例
    28python类代码编写细节
    29python运算符重载
    30python 类的设计
    31python类的高级主题
    32python异常基础
    33python异常编码细节
  • 原文地址:https://www.cnblogs.com/jcjssl/p/9441243.html
Copyright © 2011-2022 走看看