T-SQL BETWEEN problem max value first

前端 未结 2 1986
长发绾君心
长发绾君心 2021-01-24 11:40

Why this two expressions return different results? This is really stupid.

SELECT * FROM Table WHERE ID BETWEEN 3 AND 1

SELECT * FROM Table WHERE ID BETWEEN 1 AN         


        
2条回答
  •  粉色の甜心
    2021-01-24 12:08

    ID BETWEEN 3 AND 1 is simply short hand for ID >= 3 AND ID <=1 so will never return any results.

    If you look at the query plan you will see that the query text actually gets expanded out to this (Edit Or at least you can see this substitution of BETWEEN with >= / <= in queries that get auto parametrised)

提交回复
热议问题