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?
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?
Last post assumes the ROLE column is a string - is it a number?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
100 high fives to you.
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