Sorting in postgresql with different criteria to each column in case of tie Sorting in postgresql with different criteria to each column in case of tie postgresql postgresql

Sorting in postgresql with different criteria to each column in case of tie


SELECT ... ORDER BY col1 DESC, col2 ASC


select *from torder by c1 desc, c2 asc


Of course.

http://www.postgresql.org/docs/9.2/static/sql-select.html#SQL-ORDERBY

The ORDER BY clause causes the result rows to be sorted according to the specified expression(s). If two rows are equal according to the leftmost expression, they are compared according to the next expression and so on.

and later

Optionally one can add the key word ASC (ascending) or DESC (descending) after any expression in the ORDER BY clause.

one more:

Note that ordering options apply only to the expression they follow; for example ORDER BY x, y DESC does not mean the same thing as ORDER BY x DESC, y DESC.

Emphasis, my own.