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 13: Given the following scenario, what is the result of the query below? http://mysql-qotd.casperia.net/archives/164 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: urs http://mysql-qotd.casperia.net/archives/164/comment-page-1#comment-19 urs Tue, 09 Feb 2010 19:16:00 +0000 http://mysql-qotd.casperia.net/?p=164#comment-19 <b> Answer: c <code>count(column-name)</code> returns the amount of non-NULL values for the column. <code>a</code> and <code>b</code> can contain NULL values, but <code>c</code> can't. <pre>mysql> select a + b + c from tt.dfttst; +-----------+ | a + b + c | +-----------+ | 3 | | NULL | | 0 | +-----------+ 3 rows in set (0.00 sec)</pre>   Any calculation with <code>NULL</code> will result in <code>NULL</code>.</b>  
Answer:

c

count(column-name) returns the amount of non-NULL values for the column.
a and b can contain NULL values, but c can’t.

mysql> select a + b + c from tt.dfttst;
+-----------+
| a + b + c |
+-----------+
|         3 |
|      NULL |
|         0 |
+-----------+
3 rows in set (0.00 sec)

 
Any calculation with NULL will result in NULL.

 

]]>