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
    计划、执行、每天高效的活着学着
  • 相关阅读:
    android 自定义日历控件
    android 常用类
    真假空格风波
    设计模式的初衷---“委托”有感
    pymysql.err.InterfaceError: (0, '')
    微信文章收藏到有道云笔记PC版只保留了标题
    SQL Server数据库字典生成SQL
    nhibernate常见错误
    NUnit
    使用ffmpeg截取视频
  • 原文地址:https://www.cnblogs.com/huxiaoyun90/p/3950887.html
Copyright © 2011-2022 走看看