MySQL By Date
In this section, you will learn about how to fetch the data in order by date in MySQL. We can arrange the data through the ORDER BY clause. In the following example, we will create a table and view all data then we will use the ORDER BY clause.
Table: employee
CREATE TABLE `employee` ( `emp_id` int(11) NOT NULL auto_increment, `emp_name` varchar(10) character set utf8 default NULL, `emp_salary` int(11) default NULL, `emp_startDate` datetime default NULL, PRIMARY KEY (`emp_id`) ) |
Select all data in "employee" table with the following query.
Query:
SELECT * FROM employee; |
Select all the data but in date order using ORDER BY clause by executing the the following query.
Query:
SELECT * FROM employee ORDER BY emp_startDate; |
Output: