devxlogo

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 NewsItemsORDER 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 NewsItemsORDER BY DateCol DESC, AnotherCol ASC

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.