zoukankan      html  css  js  c++  java
  • 测试left join和where的优先级

    --create table tab1
    --(
    --id int,
    --size int
    --)

    --create table tab2
    --(
    --size int,
    --name varchar(10)
    --)

    --insert into tab1 values(1,10)
    --insert into tab1 values(2,20)
    --insert into tab1 values(3,30)

    --insert into tab2 values(10,'AAA')
    --insert into tab2 values(20,'BBB')
    --insert into tab2 values(20,'DDD')
    --insert into tab2 values(30,'CCC')

    --select * from tab1 left join tab2 on (tab1.size = tab2.size) where tab2.name='AAA'
    --select * from tab1 left join tab2 on (tab1.size = tab2.size and tab2.name='AAA')


    --on和where的区别
    --区别:on是对中间结果进行筛选,where是对最终结果筛选。
    --执行顺序:
    --先进行on的过滤, 而后才进行join。
    --效率:
    --如果是inner join, 放on和放where产生的结果一样,如果有outer join (left or right), 就有区别了, 因为on生效在先, 已经提前过滤了一部分数据, 而where生效在后.

  • 相关阅读:
    常用的JS代码
    静态类相关
    并查集
    RMQ
    模考题line
    递归模考题 集合
    KMP
    快速幂
    读现代软件工程之构建之法的疑问
    实验二
  • 原文地址:https://www.cnblogs.com/brainthink/p/8351912.html
Copyright © 2011-2022 走看看