在SQL查询where子句中使用多个值

时间:2011-04-13 12:31:24

标签: sql sqlite where-clause

Select Distinct
  SomeDay.SomeDayID, SomeDay.FolderName, SomeDay.FolderColor
from
  SomeDay, SomeDayEvent
where
  SomeDay.SomeDayID != 4,3,2,1;

4 个答案:

答案 0 :(得分:5)

您不能将!=用于您应使用not in的多个值,如:

Select Distinct 
    SomeDay.SomeDayID,SomeDay.FolderName,SomeDay.FolderColor 
from 
    SomeDay,SomeDayEvent 
where 
    SomeDay.SomeDayID not in (4,3,2,1);

答案 1 :(得分:4)

您不能用逗号分隔WHERE部分中的值。您必须使用IN或BETWEEN关键字。

SomeDay.SomeDayID NOT IN (1,2,3,4)

SomeDay.SomeDayID NOT BETWEEN 1 AND 4

答案 2 :(得分:0)

Select Distinct SomeDay.SomeDayID,SomeDay.FolderName,SomeDay.FolderColor from SomeDay,SomeDayEvent where SomeDay.SomeDayID NOT IN (4, 3, 2, 1)

使用IN子句。

答案 3 :(得分:0)

SomeDayID可以为空吗?你应该知道表达式

NULL NOT IN (1, 2, 3, 4)

未评估为TRUE。