Results 1 to 2 of 2

Thread: Selecting based on bitflags

  1. #1
    Join Date
    Feb 2011
    Posts
    2

    Selecting based on bitflags

    My MySQL database has a table where one column (field) is populated with 16bit numeric values (TINYINT). They are bit fields where each bit represents an independent condition.

    Is there a way to select those rows (records) where a specific bit is set?

    For example I want to select the "detail_field" from only those rows where bit 5 is high in the "bitflag_field' of the "the_table" table.

    I don't beleive a statement like this is possible because the WHERE operators do not include a bitwise "AND":

    SELECT detail_field FROM the_table WHERE bitflag_field & 32

    The operators for WHERE and HAVING don't seem to permit bit testing.

    Is there a way to select based on a bitwise comparison?

    Regards,

    Aza D. Oberman
    Washington DC

  2. #2
    Join Date
    Feb 2011
    Posts
    2

    Answered my own question

    Apparently one can use a bitmask in a WHERE statement. The "&" operator is accepted.

    Regards,

    Aza

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •