Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

mysql query and &

Codes here !

Moderators: macek, egami, gesf

mysql query and &

Postby faust » 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
faust
New php-forum User
New php-forum User
 
Posts: 109
Joined: Thu May 03, 2012 7:22 am

Re: mysql query and &

Postby Nullsig » 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
http://dev.mysql.com/doc/refman/5.0/en/bit-functions.html#operator_bitwise-and


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)
1101(13)
User avatar
Nullsig
php-forum Fan User
php-forum Fan User
 
Posts: 981
Joined: Thu Feb 17, 2011 6:52 am
Location: Racine, WI


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron