Search code examples
mysqlsign

Where does the & stand for in this query


I have a simple question,

In some old code I came up a query containing:

WHERE !(workassignment.flags&1)

I have never seen the & sign used in a query before.

It is clear what the query does to me but what is & sign and why would I use this in a query.


Solution

  • The & stands for a bitwise AND operation (see https://en.wikipedia.org/wiki/Bitwise_operation#AND). A bitwise and on the value 1 (which is what the WHERE statement uses) will return 1 when the rightmost bit in workassignment.flags is set to 1, and otherwise will return 0.

    So 1 & 1 = 1 and 0 & 1 = 0.