I am having trouble querying a SQL Anywhere Database to select one column only if all conditions are met. Here is an example: SELECT USER FROM TABLE1 WHERE DATA0 < 1 AND DATA1 = 'F' AND ID = 23 AND ID = 232 AND CITY = 'CITY1' OR CITY = 'CITY2' OR CITY = 'CITY3' So I want USER to be returned only if all the conditions are true |
Because SELECT USER FROM TABLE1 WHERE DATA0 < 1 AND DATA1 = 'F' AND ID = 23 AND ID = 232 AND (CITY = 'CITY1' OR CITY = 'CITY2' OR CITY = 'CITY3') Otherwise you will get every row that satisfies one of the OR'ed EDIT: As crb pointed out, this query will not likely return the desired result because you are requiring ID to equal both 23 and 232. These should also be in a OR/IN statement. answered 22 Aug '13, 00:20 Mikel Rychliski |
And if you want ID to be OR'ed as well, using the IN operator, you can use WHERE ID IN (23, 232) AND CITY IN ('CITY1', 'CITY2', 'CITY3') answered 22 Aug '13, 15:06 crb |