devxlogo

Sort Date in Descending Order

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

See also  The Art of AI-Generated Meeting Minutes
devxblackblue

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.

About Our Journalist