zoukankan      html  css  js  c++  java
  • SQL子句执行顺序和Join的一点总结

     SQL子句执行顺序和Join的一点总结

    1. FROM

    2. ON

    3. JOIN

    4. WHERE

    5. GROUP BY

    6. WITH CUBE or WITH ROLLUP

    7. HAVING

    8. SELECT

    9. DISTINCT

    10. ORDER BY

    11. TOP

    也就是说, 先进行on的过滤, 而后才进行join, 这样就避免了两个大表产生全部数据的笛卡尔积的庞大数据. 

    这些步骤执行时, 每个步骤都会产生一个虚拟表,该虚拟表被用作下一个步骤的输入。这些虚拟表对调用者(客户端应用程序或者外部查询)不可用。只是最后一步生成的表才会返回 给调用者。

    inner join

    找到符合 左=右 的项,不符合的不要

    left join

    左表有的都显示,右表没有的用NULL来填充

    right join

    右表有的都显示,左表没有的用NULL来填充

    full join

    全显示

    create table t_join_buyers
    (
    buyer_name varchar(10),
    buyer_id int
    )
    
    create table t_join_sales
    (
    buyer_id int,
    prod_id int,
    qty int
    )
    
    
    insert into t_join_buyers values ('jack',1)
    insert into t_join_buyers values ('tom',2)
    insert into t_join_buyers values ('anni',3)
    insert into t_join_buyers values ('poly',4)
    
    insert into t_join_sales  values (1,2,15)
    insert into t_join_sales  values (1,3,5)
    insert into t_join_sales  values (4,1,37)
    insert into t_join_sales  values (3,5,11)
    insert into t_join_sales  values (4,2,1003)
  • 相关阅读:
    针对web高并发量的处理
    外边距合并,外边距折叠
    cookie 和session 的区别:
    ng-if ng-show ng-hide 的区别
    JavaScript中的arguments,callee,caller
    git常见命令
    jQuery中.bind() .live() .delegate() .on()的区别
    为什么要使用sass
    js兼容性记录
    poj1004
  • 原文地址:https://www.cnblogs.com/roboot/p/4941856.html
Copyright © 2011-2022 走看看