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 46: What does “SELECT 1;” actually do? – MySQL Question of the Day

Skip to content

By plogi in mysql questions

In many of the questions selects without tables are used.
But what does “SELECT 1;” for example actually do?
 
(Pick 1 correct answer; or if you like a challenge try finding all)
 
a) It results in a syntax error of course!
b) With Oracle you write it like: “select 1 from dual;”
c) In DB2 you get the same result with “values 1;”.
d) The result will be 1 row with 1 column containing “1″.
 
[ Just for fun ]

Tags: , ,

Comment Feed

One Response

  1. plogi21. May 2010 @ 21:02:58


    b c d are correct.
    It works like selecting a constant from a table with 1 row.

    mysql> select 1;
    +---+
    | 1 |
    +---+
    | 1 |
    +---+
    1 row in set (0.00 sec)
    

     
    Using the same technique, you can use MySQL as a pocket-calculator:

    select 230*12+1;
    
    mysql> select 230*12+1;
    +----------+
    | 230*12+1 |
    +----------+
    |     2761 |
    +----------+
    1 row in set (0.02 sec)
    

You must be logged in to post a comment.