
- 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
Fetch a single ordered date from a column with MySQL LIMIT
To fetch a single date from a column, use “LIMIT 1. To order it, use ORDER BY clause. Let us first create a table −
mysql> create table DemoTable -> ( -> DueDate varchar(100) -> ); Query OK, 0 rows affected (1.16 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('10-06-2019'); Query OK, 1 row affected (0.42 sec) mysql> insert into DemoTable values('01-12-2016'); Query OK, 1 row affected (0.52 sec) mysql> insert into DemoTable values('31-01-2018'); Query OK, 1 row affected (0.58 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
Output
This will produce the following output −
+------------+ | DueDate | +------------+ | 10-06-2019 | | 01-12-2016 | | 31-01-2018 | +------------+ 3 rows in set (0.00 sec)
Following is the query to fetch a single ordered date from a column with MySQL LIMIT −
mysql> select *from DemoTable ORDER BY STR_TO_DATE(DueDate, '%d-%m-%Y') LIMIT 1;
Output
This will produce the following output −
+------------+ | DueDate | +------------+ | 01-12-2016 | +------------+ 1 row in set (0.00 sec)
- Related Articles
- Fetch ordered records after a specific limit in MySQL
- Retrieve MIN and MAX date in a single MySQL query from a column with date values
- MySQL query to fetch the latest date from a table with date records
- Order date records and fetch the 2nd ordered record in MySQL
- Concatenate date and time from separate columns into a single column in MySQL
- Fetch the maximum value from a MySQL column?
- Two ways to fetch maximum value from a MySQL column with numbers
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- Select a column if condition is met in MySQL to fetch records from current date and current date + 1
- MySQL LIMIT to select a single row
- Find date record after a particular date from a column with VARCHAR type in MySQL
- Display record with today and tomorrow’s date from a column with date record in MySQL
- Subtracting a number from a single MySQL column value?
- Display distinct dates in MySQL from a column with date records
- Display month names and year from a column with date records with MySQL

Advertisements