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生效在后.

  • 相关阅读:
    l1-010
    l1-009
    L1-008修改
    l1-008
    Codeforces Round #406 (Div. 2)
    求N!的长度【数学】 51nod 1058 1130
    51nod 1090 & 1267 【二分简单题】
    Codeforces Round #405 (Div. 2)
    Codeforces Round #404 (Div. 2)
    PAT 天梯赛真题集(L2、L3)
  • 原文地址:https://www.cnblogs.com/brainthink/p/8351912.html
Copyright © 2011-2022 走看看