SQL中的or与in的区别

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011944141/article/details/77968482

SQL中的or与in的区别

or与in一样的案例(条件里只有a时)

a in (1,2,3)
a = 1 or a = 2 or a = 3

or与in不一样的案例(条件里不止a时)

where a in (1,3) and b = 2
等同于
where (a = 1 or a = 3) and b = 2
等同于
where a = 1 and b = 2 or a = 3 and b = 2
等同于
where (a = 1 and b = 2) or (a = 3 and b =2 ) 

where a in (1,3) and b = 2
但不等同于
where a = 1 or a = 3 and b = 2

此处主要强调优先级的高低,复杂逻辑语句养成带()的好习惯,防止歧义,利于他人与自己后期维护。
阅读更多
想对作者说点什么?

博主推荐

换一批

没有更多推荐了,返回首页