I have a problem with sorting in postgresql. The information must be sorted in descending order according to the first column, but in case of a tie, the information must be sorted in ascending order according to the second column.
How can I accomplish this ?
You can also ORDER BY two or more columns, which creates a nested sort . The default is still ascending, and the column that is listed first in the ORDER BY clause takes precedence. The following query and Figure 3 and the corresponding query results show nested sorts.
If you want to sort the result set based on multiple columns or expressions, you need to place a comma ( , ) between two columns or expressions to separate them. Second, you use the ASC option to sort rows in ascending order and the DESC option to sort rows in descending order.
Can you arrange the result set of an SQL query on multiple columns? If you specify multiple columns, the result set is sorted by the first column and then that sorted result set is sorted by the second column, and so on.
SELECT ... ORDER BY col1 DESC, col2 ASC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With