Reputation: 103
I have a table which has 3 columns. (day, month and year)
This statement gives results in chronological order.
SELECT * FROM table WHERE = 'condition' ORDER BY year, month, day
How can I get it in the inverse order?
Upvotes: 0
Views: 49
Reputation: 476567
You can use the ASC
or DESC
keywords.
https://dev.mysql.com/doc/refman/5.0/en/order-by-optimization.html
For example:
SELECT *
FROM table WHERE = 'condition'
ORDER BY year DESC,
month DESC,
day DESC
Upvotes: 1
Reputation: 211560
You need to invert your sort order in your query:
SELECT * FROM table WHERE = 'condition' ORDER BY year DESC, month DESC, day DESC
Having separate columns for year, month, and day is counter-productive, though, as all of these could be represented in a singular DATE
type column. This can be indexed and is much faster in practice:
SELECT * FROM table WHERE ... ORDER BY date_column DESC
Upvotes: 4
Reputation: 33381
Try this:
SELECT * FROM table
WHERE = 'condition'
ORDER BY year DESC, month DESC, day DESC
Upvotes: 1