Which clause sorts query results from highest to lowest in SQL?
Correct answer
A. ORDER BY amount DESC
18 views
A. ORDER BY amount DESC
18 views
ORDER BY sorts the final result set, and DESC reverses the default ascending order, so the largest amounts appear first. GROUP BY is not a sorting clause at all: it collapses rows into groups and any apparent order is incidental and not guaranteed. NULL placement in sorted output varies by database, so explicit NULLS LAST is needed for portable behaviour.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is A? Ask here and get an explanation.