Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using multiple values in SQL query where clause

Select Distinct
  SomeDay.SomeDayID, SomeDay.FolderName, SomeDay.FolderColor
from
  SomeDay, SomeDayEvent
where
  SomeDay.SomeDayID != 4,3,2,1;
like image 811
Rupesh Avatar asked Apr 13 '11 12:04

Rupesh


2 Answers

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);
like image 87
Harry Joy Avatar answered Oct 27 '22 10:10

Harry Joy


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
like image 20
halfdan Avatar answered Oct 27 '22 11:10

halfdan