CodingNeed.

1 · Read and filter · 8 MIN

Sort deliberately

Sort deliberately.

ORDER BY chooses the result order. ASC is ascending and DESC descending. LIMIT caps returned rows. When sorting values that may tie, add a unique column to make the order deterministic.

Think of a spreadsheet: select columns, keep relevant rows, and summarize the result.

Read the example

SELECT amount FROM expenses ORDER BY amount ASC;
Check the expected output
[[3],[5],[7]]

Your challenge

Return the two highest amounts in descending order.

Common trap

Row order is only guaranteed with ORDER BY.

Next lesson: Aggregate a result →

Essential cookies keep your account signed in. Optional analytics is not configured on this site. Your choice does not affect access to lessons.

Read the Privacy Policy. You can change this choice in the footer.