SQL中的or与in的区别

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

此处主要强调优先级的高低,复杂逻辑语句养成带()的好习惯,防止歧义,利于他人与自己后期维护。
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011944141/article/details/77968482
文章标签: sql or in
个人分类: postgreSQL
想对作者说点什么? 我来说一句

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

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭