'ORDER BY' Clause in SQL

‘My exercise’

Hi peeps,

I was doing this exercise (above link) on ‘ORDER BY’ clause.
As this is pretty much like sorting in Microsoft ‘Excel’, is it possible to sort by a few levels?
e.g. Sort column A, then by column B, then by column C, etc.

Thanks in advance!

1 Like

Hi @viciouscode, short answer: yes, you can.
SELECT * FROM TABLE1 ORDER BY col 1 DESC, col2

Column2 would sort ASC (b/c that’s the default). You can also add a CASE statement:
Here’s more of an explanation:
https://stackoverflow.com/questions/2051162/sql-multiple-column-ordering

5 Likes

wow, thanks a lot lisalisaj! :slight_smile:

1 Like