
- 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
Order By date ASC in MySQL?
You can use STR_TO_DATE() function. Let us first create a table −
mysql> create table DemoTable ( AdmissionDate varchar(200) ); Query OK, 0 rows affected (1.19 sec)
Insert records in the table using insert command −
mysql> insert into DemoTable values('12-01-2019'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values('14-12-2016'); Query OK, 1 row affected (0.15 sec) mysql> insert into DemoTable values('26-04-2018'); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable values('31-05-2013'); Query OK, 1 row affected (0.30 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable;
This will produce the following output −
+---------------+ | AdmissionDate | +---------------+ | 12-01-2019 | | 14-12-2016 | | 26-04-2018 | | 31-05-2013 | +---------------+ 4 rows in set (0.00 sec)
Following is the query to sort order by date ASC −
mysql> select *from DemoTable ORDER BY STR_TO_DATE(AdmissionDate,'%d-%m-%Y') ASC;
This will produce the following output −
+---------------+ | AdmissionDate | +---------------+ | 31-05-2013 | | 14-12-2016 | | 26-04-2018 | | 12-01-2019 | +---------------+ 4 rows in set (0.00 sec)
- Related Articles
- Implement MySQL ORDER BY without using ASC or DESC?
- MySQL ORDER BY ASC and display NULLs at the bottom?
- MySQL ORDER BY Date field not in date format?
- MySQL query to display ASC order in number column?
- Sort by date & time in descending order in MySQL?
- Displaying only a list of records in ASC order with MySQL
- Order by date set with varchar type in MySQL
- How to order by date and time in MySQL?
- Select last 3 rows from database order by id ASC?
- Wrap around to first value and implement MySQL ORDER BY ASC and DESC in a single query
- How to sort varchar numeric columns by DESC or ASC in MySQL?
- How to Order by date in MySQL but place empty dates in the end?
- Order by selected record in MySQL?
- Resolve Syntax error near “ORDER BY order DESC” in MySQL?
- MySQL Order by with case?

Advertisements