MySQL By Date

In this section, you will learn about how to fetch the data in order by date in MySQL.


 
Ads

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:

Advertisements

Share on Google+Share on Google+

MySQL By Date

Posted on: January 20, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: MySQL By Date   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Chiranjit Mondal
August 23, 2012
oracle

emp_startDate` datetime default NULL, it is wrong;what is datatype of date field;

Ads

 

Ads