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


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.

Updated on: 30-Jan-2020

48 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements