LIMIT keeps the first rows from an already ordered result.

highlighted = computed this step

Input table

Start with the same five order rows.

Orders\text{Orders}
Ordersorder_idcategoryamounto1book30o2pen12o3book12o4paper45o5pen30

Order query

Order by amount descending with an order_id tie-breaker, then keep the first rows.

ORDER BY amount DESC LIMIT\text{ORDER BY amount DESC LIMIT}
ORDER BY amount descending LIMIT 3limit 3arity 3 rows 3order by amount desc,order_id ascarity 3 rows 5Ordersarity 3 rows 5

Ordered output

The result is the top rows from that explicit order.

top three rows\text{top three rows}
Ordered outputorder_idcategoryamounto4paper45o1book30o5pen30