mysql query and &

Codes here !

Moderators: egami, macek, gesf

Post Reply
New php-forum User
New php-forum User
Posts: 109
Joined: Thu May 03, 2012 7:22 am

Fri May 18, 2012 1:55 am

Can anybody tell me what & means in an SQL query. Example:

Code: Select all

SELECT blabla 
FROM blabla
WHERE id = 5 AND flag&2=2

User avatar
php-forum Fan User
php-forum Fan User
Posts: 979
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI

Fri May 18, 2012 6:39 am

When the ampersand (&) is used like this in a query it is a "Bitwise AND":

Code: Select all
In this case it is saying that if the binary translation of your "flag" variable ends in "10" [Binary 2] it will return true.

In the example in the link I shared the values are
11101 (29)
& 1111 (15)

Post Reply