DUAL
Most of the time when you are using SQL you will be selecting against a table in your database. But there are the odd occassions where you don't actually want to select something from a table but still display information.
In Oracle this is handled by the DUAL table. DUAL is a single row all purpose table which allows you to issue a select statement on values which are not stored in an actual table. Take for example the sysdate function which returns the current date.
SQL> select sysdate from dual;
SYSDATE
---------
23-AUG-05
MySQL has full support for the DUAL table also.
mysql> select curdate() from dual;
+------------+
| curdate() |
+------------+
| 2005-08-23 |
+------------+
1 row in set (0.00 sec)
However MySQL doesn't really need the DUAL table to return values. You can simply issue a select statement that doesn't have a from clause. It's perfectly legal and in fact the most common way to select values that don't belong in a table.
mysql> select curdate();
+------------+
| curdate() |
+------------+
| 2005-08-23 |
+------------+
1 row in set (0.00 sec)
You can use this method to return information about the MySQL server or perform calculations. It's especially good for testing SQL you are going to use in the select section of an SQL statement.
Warning : It should be noted that you shouldn't issue anything other than select statements against the DUAL table, issuing INSERTS, UPDATES and worst of all DELETES against DUAL can have at least undesirable results.
0 Comments:
Post a Comment
<< Home