zoukankan      html  css  js  c++  java
  • 【MYSQL】SQL 的join 区别

    ----------------------INNER JOIN--------------------------- 
    1. 三表联合查询
    select XX,XX  from a , b , c 
    笛卡尔积,等同于cross join
     
    2. cross join
    --列出两边所有组合,也叫笛卡尔集A.Rows * B.Rows
    select *
    from Sales S cross join Customers C
     
    3. inner join = join
    --两边都有的才筛选出来
    select *
    from Sales S inner join Customers C
    on S.Cust_Id = C.Cust_Id
     
    ----------------------OUTER JOIN--------------------------- 
    4. left join = left outer join
    --以左边的表为主表,列出主表所有记录,能匹配就匹配,不匹配的用NULL列出
    select * from Customers c left join sales s
    on c.cust_id = s.cust_id
     
    5. right join = right outer join
    --以右边的表为主表,列出主表所有记录,能匹配就匹配,不匹配的用NULL列出
    select * from Customers c right join sales s
    on c.cust_id = s.cust_id
     
    6. Full join = full outer join
    --两边都列出来,能匹配就匹配,不匹配的用NULL列出
    select *
    from Sales S full outer join Customers C
    on S.Cust_Id = C.Cust_Id
     
    示例======================
     
    SELECT A.id, rule_id, alarm_name, filter_key, A.subtype, B.name
    FROM (
    A
    LEFT JOIN B ON A.subtype = B.id
    )
    JOIN C ON C.alarm_type = A.type
    计划、执行、每天高效的活着学着
  • 相关阅读:
    单例设计模式
    使用JfreeChart生成统计图
    session的生命周期
    json
    struts2 ognl标签使用
    集合小结
    多线程
    内部类和匿名内部类
    模版方法设计模式
    mac中yeoman构建你的项目
  • 原文地址:https://www.cnblogs.com/huxiaoyun90/p/3950887.html
Copyright © 2011-2022 走看看