开发者

Using multiple values in SQL query where clause

开发者 https://www.devze.com 2023-02-25 02:06 出处:网络
Select Distinct SomeDay.SomeDayID, SomeDay.FolderName, SomeDay.FolderC开发者_运维知识库olor from
Select Distinct
  SomeDay.SomeDayID, SomeDay.FolderName, SomeDay.FolderC开发者_运维知识库olor
from
  SomeDay, SomeDayEvent
where
  SomeDay.SomeDayID != 4,3,2,1;


You can not use != for multiple values for that you should use not in like:

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


You can't separate values in the WHERE part by comma. You have to use the IN or BETWEEN keyword.

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

or

SomeDay.SomeDayID NOT BETWEEN 1 AND 4


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

Use the IN clause.


Is SomeDayID nullable? You should be aware that the expression

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

does not evaluate to TRUE.

0

精彩评论

暂无评论...
验证码 换一张
取 消