

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 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
- Fetch the maximum value from a MySQL column?
- Order date records and fetch the 2nd ordered record in MySQL
- MySQL LIMIT to select a single row
- Concatenate date and time from separate columns into a single column in MySQL
- Subtracting a number from a single MySQL column value?
- Two ways to fetch maximum value from a MySQL column with numbers
- Fetch specific rows from a MySQL table with duplicate column values (names)?
- Find date record after a particular date from a column with VARCHAR type in MySQL
- Display distinct dates in MySQL from a column with date records
- Fetch random rows from a table with MySQL
- How to fetch only a single result from a table in Java-MySQL?
- Select a column if condition is met in MySQL to fetch records from current date and current date + 1
Advertisements