Link to home
Start Free TrialLog in
Avatar of mynamebecory2
mynamebecory2

asked on

Searching for a 'binary mask' in MySQL

I have a field in mysql that is stored as a binary value.  This field represents multiple roles a person can have and the 'stacking' of those roles.

Example;
admin - 00000001
user   - 00000010
mod      00000100

Someone that is an admin & moderator would be 00000101.

Given this query, only someone with an admin role is returned:
Select first_name, last_name
From users
where role  = '00000001';

Is it possible?
Avatar of spoxox
spoxox
Flag of Canada image

Not sure what your goal is.
If you want to discover all with administrator rights, even if they have other rights as well, you can use

WHERE ROLE LIKE '_______1'

Character      Description
%               Matches any number of characters, even zero characters
_               Matches exactly one character

http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html
Last post assumes the ROLE column is a string - is it a number?
ASKER CERTIFIED SOLUTION
Avatar of theGhost_k8
theGhost_k8
Flag of India 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
Avatar of mynamebecory2
mynamebecory2

ASKER

100 high fives to you.