bodesam bodesam - 1 year ago 73
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 Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download