ORDER BY sorts the final result of a query and can use columns from any table included in the query.
Business reports often require joined data to be displayed in a specific order.
Display customers and their orders from the highest order amount to the lowest.
SELECT
c.CustomerName,
o.OrderID,
o.OrderAmount
FROM Customers c
INNER JOIN Orders o
ON c.CustomerID = o.CustomerID
ORDER BY o.OrderAmount DESC;
ORDER BY with JOIN is common in sales reports, customer analysis, transaction reports, and management dashboards.
- ORDER BY sorts the final JOIN result.
- Columns from joined tables can be used.
- ASC sorts ascending.
- DESC sorts descending.
- Multiple sorting columns can be specified.
Can ORDER BY use a column from a joined table?
Yes. ORDER BY can sort using columns from any table available in the query.
Does ORDER BY change the JOIN result?
No. ORDER BY changes only the presentation order of the result.