For getting the most recent date from a table, we need to provide the name of the column, having a date as value, as the argument of MAX() function. Similarly, forgetting the oldest date from a table, we need to provide the name of a column, having a date as value, as the argument of MIN() function. To understand it, consider the following example of table ‘Collegedetail’, having the following details −
mysql> Select * from collegedetail; +------+---------+------------+ | ID | Country | estb | +------+---------+------------+ | 111 | INDIA | 2010-05-01 | | 130 | INDIA | 1995-10-25 | | 139 | USA | 1994-09-25 | | 1539 | UK | 2001-07-23 | | 1545 | Russia | 2010-07-30 | +------+---------+------------+ rows in set (0.00 sec)
Now, MIN() and MAX() function can be used to retrieve the oldest college and newest college respectively from the above table, as follows −
mysql> Select MIN(estb), MAX(estb) from collegedetail; +------------+------------+ | MIN(estb) | MAX(estb) | +------------+------------+ | 1994-09-25 | 2010-07-30 | +------------+------------+ 1 row in set (0.19 sec)