T-SQL reference › ORDER BY

ORDER BY in SQL Server

SQL Server does not promise order unless you say ORDER BY. “Looks sorted” today is not a contract.

Biggest first, then newest

SELECT TOP (10) order_id, order_date, total_amount
FROM Orders
ORDER BY total_amount DESC, order_date DESC;

Second column is the tie-break. See TOP.

Try it on Harbour & Co

Sandra Okafor (Managing Director) needs this now: “Board pack: our 5 biggest orders ever. Order, customer, amount.” Write the query, run it, send the results. On the paid plan.

Take the ticket →

Learn it on a real ticket

Monday is free on WorkSQL. A colleague’s ticket lands, you write the T-SQL, we mark it. No videos. Five minutes.

Clock in free See Monday’s tickets