Link to home
Start Free TrialLog in
Avatar of imaginative
imaginative

asked on

MySQL Query using the IN operator

I think the 'IN' operator is what I need here, but say I have fictitious columns named the following:

user_id, can_write, can_read, can_jump, can_walk

anything prefixed with can_* is a tinyint which is either a 1 or 0, mimicking the act of boolean.  What's the best way for me to select all rows in this fictitious table where ANY of the columns prefixed with can_* are toggled to '1'?

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of bmilli
bmilli

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bmilli
bmilli

To be clear, the in clause will not help you do what you want.
You could do the following, but it really is not efficient.

select user_id, can_write, can_read, can_jump, can_walk
from table
where
   can_write in (1)  or  
   can_read in (1)  or
   can_jump in (1)  or
   can_walk in (1)
SOLUTION
Avatar of Terry Woods
Terry Woods
Flag of New Zealand image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That may require MySQL version > 5 by the way for the column_name query to work