What MySQL returns if I write only one value in the enclosed set of unit values for compound INTERVAL unit?

MySQLMySQLi Database

In this case, MySQL will take into consideration right most unit given in compound INTERVAL unit. It will return the output after calculating the interval on the basis of single value provided in the enclosed set of unit values. The following example will clarify it −

mysql> Select TIMESTAMP('2017-10-22 04:05:36' + INTERVAL '2 ' year_month) AS 'Only Month Value Changed';
+--------------------------+
| Only Month Value Changed |
+--------------------------+
| 2017-12-22 04:05:36      |
+--------------------------+
1 row in set (0.00 sec)

The query above changes the month (right most in compound INTERVAL unit) from 10 to 12 based on the single value i.e. 2 provided in the enclosed set of unit values.

raja
Published on 19-Feb-2018 15:34:34
Advertisements