1

Simple mysql question i am trying to write a query based on a criteria of four values however it does not seem to be working, here is and example of the query:

select * from table_1 where c=0 d=0 a=0 u=0 or c=1 d=1 a=1 u=1
4

2 回答 2

11

Your WHERE logic is incorrect:

select * 
from table_1 
where (c=0 and d=0 and a=0 and u=0) 
or (c=1 and d=1 and a=1 and u=1)

You need to group your statements together in parenthesis and still use AND for any conditions that need to be grouped together.

于 2012-07-09T13:58:03.623 回答
2

Or, if these are always 0 and 1, you can use a trick to shorten the query:

where c+d+a+u = 0 or c*d*a*u = 1
于 2012-07-09T14:15:52.403 回答