Searching for a 'binary mask' in MySQL

Posted on 2009-04-30
Last Modified: 2013-12-01
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.

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?
Question by:mynamebecory2
    LVL 11

    Expert Comment

    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
    LVL 11

    Expert Comment

    Last post assumes the ROLE column is a string - is it a number?
    LVL 21

    Accepted Solution

    LVL 1

    Author Closing Comment

    100 high fives to you.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    I. Introduction There's an interesting discussion going on now in an Experts Exchange Group — Attachments with no extension ( This reminded me of questions tha…
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    This video discusses moving either the default database or any database to a new volume.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now