Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL Server
Expertise: Beginner
Jun 28, 2000

Sort Date in Descending Order

Question:
My SQL statement at the moment is:
SELECT * FROM NewsItems
How do I sort the dates in descending order?

Answer:
Use the ORDER BY clause to sort the results of a SELECT statement. The ORDER BY clause orders the results by the specified column. It sorts in ascending order by default, so you'll have to specify descending order like this:

SELECT * FROM NewsItems
ORDER BY DateCol DESC
The DESC applies only to the column preceding it so you could order by date in descending order and by another column in ascending order.
SELECT * FROM NewsItems
ORDER BY DateCol DESC, AnotherCol ASC
DevX Pro
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date