11/07: MySQL > SQL Expressions 2
Temporal Expressions
To perform interval arithmetic, use the INTERVAL keyword and a unit value:
SELECT '2007-12-31' + INTERVAL 10 DAY; (or INTERVAL 10 DAY + '2007-12-31')
SELECT '2007-12-31' - INTERVAL 10 DAY;
* Not DAYS.
The INTERVAL can be specified in units such as SECOND, MINUTE, HOUR, DAY, MONTH or YEAR.
NULL Values
Use of NULL values in arithmetic or comparison operations normally produces NULL results. Even comparing NULL to itself results in NULL.
The following statements return NULL:
SELECT NULL + 1, NULL < 1;
SELECT NULL = 1, NULL != NULL;
SELECT NULL LIKE '%', NULL LIKE NULL;
In MySQL, <=> operator works like = and this works with NULL operand.
NULL values sort together (ORDER BY), group together (GROUP BY), and are not distinct.
Expressions that cannot be evaluated (such as 1/0) produce NULL as a result, but the result NULL value cannot be inserted. This is controlled by ERROR_FOR_DIVISION_BY_ZERO mode.
To perform interval arithmetic, use the INTERVAL keyword and a unit value:
SELECT '2007-12-31' + INTERVAL 10 DAY; (or INTERVAL 10 DAY + '2007-12-31')
SELECT '2007-12-31' - INTERVAL 10 DAY;
* Not DAYS.
The INTERVAL can be specified in units such as SECOND, MINUTE, HOUR, DAY, MONTH or YEAR.
NULL Values
Use of NULL values in arithmetic or comparison operations normally produces NULL results. Even comparing NULL to itself results in NULL.
The following statements return NULL:
SELECT NULL + 1, NULL < 1;
SELECT NULL = 1, NULL != NULL;
SELECT NULL LIKE '%', NULL LIKE NULL;
In MySQL, <=> operator works like = and this works with NULL operand.
NULL values sort together (ORDER BY), group together (GROUP BY), and are not distinct.
Expressions that cannot be evaluated (such as 1/0) produce NULL as a result, but the result NULL value cannot be inserted. This is controlled by ERROR_FOR_DIVISION_BY_ZERO mode.