• SQL语法——Join详解


    一、INNER JOIN

    用法:

    select column_name(s)
    from table 1
    INNER JOIN table 2
    ON
    table 1.column_name=table 2.column_name

    例子:

     两个表:three,user

    select* from three inner join user;

    select* from three inner join user on three.id = user.id;

    二、LEFT JOIN

     用法:

    select column_name(s)
    from table 1
    LEFT JOIN table 2
    ON table 1.column_name=table 2.column_name

    例子:

    select * from three left join user on three.id=user.id;
    

     三、RIGHT JOIN

     用法:

    select column_name(s)
    from table 1
    RIGHT JOIN table 2
    ON table 1.column_name=table 2.column_name
    

    例子:

    select * from three right join user on three.id=user.id;

    四、FULL OUTER JOIN

    用法:

    select column_name(s)
    from table 1
    FULL OUTER JOIN table 2
    ON table 1.column_name=table 2.column_name
    

    例子:

    select * from three full outer join user on three.id=user.id;

     mysql 报错不支持full join ,但是可以用下面的这种写法取代:

    select * from three left outer join user on three.id=user.id union select * from three right outer join user on three.id=user.id;

     参考资料:

    https://www.cnblogs.com/reaptomorrow-flydream/p/8145610.html

  • 相关阅读:
    机器学习项目流程(二)探索并可视化数据
    机器学习项目流程(一)初探数据集
    数据类型.md
    keepalived.md
    LVS.md
    tomcat多实例.md
    LANMP常用配置.md
    php-fpm配置参数.md
    Nginx学习.md
    Redis.md
  • 原文地址:https://www.cnblogs.com/chrysanthemum/p/12026269.html
Copyright © 2020-2023  润新知