dames
dames

Reputation: 1481

mysql query using 'OR' syntax

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

Upvotes: 1

Views: 4232

Answers (2)

Gordon Linoff
Gordon Linoff

Reputation: 1271151

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

Upvotes: 2

John Conde
John Conde

Reputation: 219924

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.

Upvotes: 11

Related Questions