
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
MySQL query to fetch the latest date from a table with date records
Let us first create a table −
mysql> create table DemoTable ( DueDate date ); Query OK, 0 rows affected (0.56 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('2018-10-01'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('2016-12-31'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable values('2019-07-02'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values('2015-01-12'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable values('2019-04-26'); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+------------+ | DueDate | +------------+ | 2018-10-01 | | 2016-12-31 | | 2019-07-02 | | 2015-01-12 | | 2019-04-26 | +------------+ 5 rows in set (0.00 sec)
Let’s say the current date is 2019-08-15. Now we will fetch the latest date −
mysql> select *from DemoTable order by DueDate DESC limit 1;
This will produce the following output −
+------------+ | DueDate | +------------+ | 2019-07-02 | +------------+ 1 row in set (0.03 sec)
- Related Articles
- MySQL time period query to fetch date records from interval of 14 weeks from current date?
- UNIX_TIMESTAMP with date in MySQL query to fetch records after a specific date in different format?
- MySQL query to fetch date records greater than the current date after adding days with INTERVAL?
- How to change the date in a table with date records with MySQL?
- MySQL query to select records with a particular date?
- MySQL query to fetch date with year and month?
- Add 30 days to date in a MySQL table with arrival date records
- Find the difference between current date and the date records from a MySQL table
- MongoDB query to fetch date records (ISODate format) in a range
- How to compare the first date and the last date from a MySQL column with date records?
- Filter dates from a table with DATE and NULL records in MySQL
- MySQL query to select records with a particular date and time?
- How to find last date from records with date values in MySQL?
- MySQL query to subtract date records with week day and display the weekday with records
- Select a column if condition is met in MySQL to fetch records from current date and current date + 1

Advertisements