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
Question 22: What will the following query return? – MySQL Question of the Day

Skip to content

By urs in mysql questions

 

create table mintst (n int not null default 0);
 
select min(n),max(n) from mintst;
 
a) 0, 0
b) 0, 255
c) NULL, NULL
d) 0, NULL

 
[ SQL Expressions (15%) - NULL Values ]
 

Tags: , ,

Comment Feed

One Response


  1.  
    Answer:
     
    c
     
    The MIN/MAX values for an empty table are undefined and therefore NULL. I’ve seen statistics and reporting software abort because of empty tables ;-) You can use COALESCE() or IFNULL() to catch those NULL-values.
     
    mysql> select min(n),max(n) from mintst;
    +--------+--------+
    | min(n) | max(n) |
    +--------+--------+
    | NULL | NULL |
    +--------+--------+
    1 row in set (0.00 sec)

     

You must be logged in to post a comment.