Page 1 of 1

and or in query

Posted: Sat Nov 12, 2005 8:06 am
by shiznatix
i am making a dynamic select query but what i wanna do is have a and with some or's in it. i wanna do somthing like

Code: Select all

WHERE
  table1 = gwarrrr
AND
  table2 = bloort
AND
  table3 = oneht
AND
  table4 = one
    OR
  table4 = two
    OR
  table4 = three
but i want to not have all those OR 1 of the table4's i want it to be like AND if 1 of those 4's are equal to one of the values. understand?

Posted: Sat Nov 12, 2005 10:47 am
by timvw
Thats why you should use brackets... To show us which parts belong together... See the differences?

WHERE a OR b AND c
WHERE a OR (b AND c)
WHERE (a OR b) AND c

So your query would be something like

WHERE a AND (b = val1 OR b = val2 or b = val3)

With the IN operator you can write this as:

WHERE a AND (b IN (1, 2, 3))

Posted: Sat Nov 12, 2005 10:50 am
by shiznatix
gotcha, many thanks