如何使用多个值过滤列

时间:2014-04-16 15:33:20

标签: sql sqlite

如何使用多个值过滤列col1

select * from table where col1=2 and col1=4 and  userID='740b9738-63d2-67ff-ba21-801b65dd0ae1' 

我累了

select * from table where col1=2 or col1=4 and  userID='740b9738-63d2-67ff-ba21-801b65dd0ae1'

两个查询的结果都不正确

第一个给出零结果 第二个给出了3个结果

正确的是2个结果

sql将针对sqlite db运行。

1 个答案:

答案 0 :(得分:2)

AND之前评估

OR,因此您的查询等同于:

select * 
from table 
where col1=2 or (col1=4 and  userID='740b9738-63d2-67ff-ba21-801b65dd0ae1')

混合ANDOR时,您需要明确对条件进行分组:

select * 
from table 
where (col1=2 or col1=4) and  userID='740b9738-63d2-67ff-ba21-801b65dd0ae1'