2014-04-16 41 views
0

如何過濾列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個結果

the co rrect是2結果

sql將針對sqlite數據庫運行。

回答

2

ANDOR之前評估,所以您的查詢等效於:

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'