bodesam bodesam - 3 months ago 9
SQL Question

SQL Sort three columns together - day, month, year

Is there a way to write an SQL order by query to sort three columns(day,month,year) together not individually. This seems tricky because 2 12 2016 should come before 1 12 2017 if in ascending order.
How do I go about this?

Answer

You would just include three keys in the order by:

order by year, month, day

Note: These are ANSI standard keywords (think extract()). Hence, they are poor choices for column names.

Comments