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

  • Home
  • SEARCH
  • 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 7540331
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:36:57+00:00 2026-05-30T07:36:57+00:00

im trying to use MySQL bitwise operations for my query and i have this

  • 0

im trying to use MySQL bitwise operations for my query and i have this example:

table1
id      ptid
1       3
2       20
3       66
4       6

table2
id     types
1      music
2      art
4      pictures
8      video
16     art2
32     actor
64     movies
128    ..
...

now, the id = 3 from table1 is ’66’, witch means that it has 64 or movies and 2 or art

but

doesn’t he also have 32 or actor twice and 2 or art ??

hope you see where my confusion is. How do i control what result i want back. In this case i want 64 or movies and 2 or art.

But sometimes i want three id's from table2 to belong to an id from table1

any ideas?

Thanks

  • 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-05-30T07:36:58+00:00Added an answer on May 30, 2026 at 7:36 am

    Using bitwise OR

    The following query returns all the items from table 2 in 66:

    SELECT *
    FROM table2
    WHERE id | 66 = 66
    

    But 32 + 32 = 64?

    Though 32 + 32 = 64, it doesn’t affect us.

    Here’s 64 in binary:

    01000000
    

    Here’s 32 in binary:

    00100000
    

    Here’s 2 in binary:

    00000010
    

    It’s the position of the 1 that we use in this case, not the value. There won’t be two of anything. Each flag is either on or off.

    Here’s 66 in binary. Notice that 64 and 2 are turned on, not 32:

    01000010
    

    Using bitwise AND instead of OR

    Another way to write the query is with bitwise AND like this:

    SELECT *
    FROM table
    WHERE id & 66 <> 0
    

    Since 0 = false to MySQL, it can be further abbreviated like this:

    SELECT *
    FROM table
    WHERE id & 66
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to use this MySQL query: SET @a:=0; UPDATE tbl SET sortId=@a:=@a+1
I am trying to use jQuery with MYSQL and I wrote something like this
Hi im trying to use Sql within MySql to sort some values and this
I am trying use MySql and Entity Framework, using Connector/Net 6.1 with this as
I use MySQL server version 5.5.14 and now I am trying this simple SQL
i have use mysql database . my problem is that i run a query
This is a weird one. I am trying to use Views in MySQL (I'm
I am trying to use MySql Connector 6.2.2.0 for membership and role providers. The
I'm trying to use ON CASCADE DELETE in mysql db but I can't make
I don't use php or mysql but I am trying to upgrade a phpbb

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.