How can we find the most recent and most oldest date from a table with the help of MySQL MAX() and MIN() functions?

MySQLMySQLi Database

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)
raja
Published on 21-Feb-2018 12:22:09
Advertisements