[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 574
  • Last Modified:

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?
0
mynamebecory2
Asked:
mynamebecory2
  • 2
1 Solution
 
spoxoxCommented:
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
0
 
spoxoxCommented:
Last post assumes the ROLE column is a string - is it a number?
0
 
K VDatabase ConsultantCommented:
0
 
mynamebecory2Author Commented:
100 high fives to you.
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now