Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8091529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:05:07+00:00 2026-06-05T20:05:07+00:00

I have users table and want to SELECT some rows by bitmask criteria. I’ll

  • 0

I have users table and want to SELECT some rows by bitmask criteria. I’ll try to explain my problem with small example.

Structure of table users

user_id             int           [primary key, auto_increment]
user_email          varchar(200)    
user_privileges     int

Note: It has more fields but they are irrelevant for this question.

Filled table may look like this

+---------+--------------------+-----------------+
| user_id | user_email         | user_privileges |  << binary
+---------+--------------------+-----------------+
| 1       | john@example.com   | 165             |  10100101
| 2       | max@example.com    | 13              |  00001101
| 3       | trevor@example.com | 33              |  00100001
| 4       | paul@example.com   | 8               |  00001000
| 5       | rashid@example.com | 5               |  00000101
+---------+--------------------+-----------------+

Now I want to SELECT users by specific privileges bitmask (by user_privileges column).

For example:

  • bitmask=1 [00000001] would select user-ids 1, 2, 3 and 5
  • bitmask=9 [00001001] would select user-id 2 only
  • bitmask=5 [00000101] would select user-ids 1, 2 and 5
  • bitmask=130 [10000010] would select none

My question: Is it possible from query or I have to go all users one-by-one and check this value from PHP code? Also, is it possible if field user_privileges is text, containing hexadecimal numbers, instead of integers? I need working mysql query example.

Note: This is just a simple example with 8-bit privilege-set. In real environment it may have larger sets (greater integers, more bytes). Creating separate column for each privilege state works fine, but that’s not possible solution. I’d rather work with hex values, but integers are fine too, something is better than nothing.

Thanx in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:05:08+00:00Added an answer on June 5, 2026 at 8:05 pm

    […] want to SELECT some fields

    Wrong. You want to select some Rows. Columns are usually called fields.

    You are supposed to read the Documentation: Bit Functions are documented for mysql.

    So you can try:

    Select * from users WHERE (user_privileges & 1) >0

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have users table and i have posts table i want select from users
I have a users table and a friends table. I want to get the
I have about 1 million data in users table. Now I want each user
[using SQL Server 2005] I have a table full of users, I want to
I have a table of vehicles with registration numbers, and want to select a
I have a table with a header and some rows. Each row has its
Heres my scenario. I have a table with 3 rows I want to return
Simple example: I want to have some items on a page (like divs or
I have a user-defined table type. I want to check it's existence before editing
I have this table: User id INT PK login VARCHAR UNIQUE I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.