Skip to main content

Order By

The ORDER BY keyword is used to sort the result-set in ascending or descending order.

Order by contain asc and desc, for ordering the result. Default ASC

Order by on multiple columns:

select * from loans order by status, principal desc; (For each loan status, show the biggest loans first)

select * from loans order by principal desc, status; (Show me the largest loans overall, regardless of status)

both return the same rows, but the ordering logic is different