Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4991

Warning: Creating default object from empty value in /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php on line 4993

Warning: Cannot modify header information - headers already sent by (output started at /www/htdocs/v030397/mysql-qotd/wp-content/plugins/sitepress-multilingual-cms/sitepress.class.php:4991) in /www/htdocs/v030397/mysql-qotd/wp-includes/feed-rss2-comments.php on line 8
Comments on: Question 85: What is the result of the query? http://mysql-qotd.casperia.net/archives/562 mysql 5.0/5.1 questions for learning purposes Fri, 06 Aug 2010 16:56:36 +0000 http://wordpress.org/?v=abc hourly 1 By: plogi http://mysql-qotd.casperia.net/archives/562/comment-page-1#comment-98 plogi Fri, 06 Aug 2010 16:56:36 +0000 http://mysql-qotd.casperia.net/?p=562#comment-98 <b> <small><pre> select n,n and 3,n & 3, n mod 4, n and false,n and true from (select 0 n union select 1 union select 2 union select 3 union select 4 union select 5 union select 6 union select 7 union select null) v1; +------+-------+------+-------+-------+-------+ | n | n and | n & | n mod | n and | n and | | | 3 | 3 | 4 | false | true | +------+-------+------+-------+-------+-------+ | 0 | 0 | 0 | 0 | 0 | 0 | | 1 | 1 | 1 | 1 | 0 | 1 | | 2 | 1 | 2 | 2 | 0 | 1 | | 3 | 1 | 3 | 3 | 0 | 1 | | 4 | 1 | 0 | 0 | 0 | 1 | | 5 | 1 | 1 | 1 | 0 | 1 | | 6 | 1 | 2 | 2 | 0 | 1 | | 7 | 1 | 3 | 3 | 0 | 1 | | NULL | NULL | NULL | NULL | 0 | NULL | +------+-------+------+-------+-------+-------+ 9 rows in set (0.00 sec) </pre></small> And, did you get it right? "3" is a true value, that makes "n and true" and "n and 3" the same. The modulo and bit-operations are obvious and so is the fact, that an operation with NULL results in NULL. For me the most interesting part is, that TRUE AND NULL is NULL, where as FALSE AND NULL is FALSE. </b>
select n,n and 3,n & 3, n mod 4, n and false,n and true
from (select 0 n union select 1 union select 2 union
      select 3 union select 4 union select 5 union
      select 6 union select 7 union select null) v1;

+------+-------+------+-------+-------+-------+
| n    | n and | n &  | n mod | n and | n and |
|      | 3     | 3    | 4     | false | true  |
+------+-------+------+-------+-------+-------+
|    0 |     0 |    0 |     0 |     0 |     0 |
|    1 |     1 |    1 |     1 |     0 |     1 |
|    2 |     1 |    2 |     2 |     0 |     1 |
|    3 |     1 |    3 |     3 |     0 |     1 |
|    4 |     1 |    0 |     0 |     0 |     1 |
|    5 |     1 |    1 |     1 |     0 |     1 |
|    6 |     1 |    2 |     2 |     0 |     1 |
|    7 |     1 |    3 |     3 |     0 |     1 |
| NULL |  NULL | NULL |  NULL |     0 |  NULL |
+------+-------+------+-------+-------+-------+
9 rows in set (0.00 sec)


And, did you get it right?
“3″ is a true value, that makes “n and true” and “n and 3″ the same. The modulo and bit-operations are obvious and so is the fact, that an operation with NULL results in NULL.
For me the most interesting part is, that TRUE AND NULL is NULL, where as FALSE AND NULL is FALSE.

]]>