Beginner

548. JOIN with ORDER BY

Learn how ORDER BY can sort results after combining data from multiple tables.

📘 Lesson 548 of 728 ⏱ 10 min 🎯 Beginner

ORDER BY sorts the final query result using one or more columns. These columns can come from any table included in the query when they are available to the SELECT statement.

Reports often need joined data displayed in a meaningful order such as highest sales, latest transaction, or alphabetical customer name.

Display customers and their orders with the highest order amount first.

SQL
SELECT
    c.CustomerName,
    o.OrderID,
    o.OrderAmount
FROM Customers c
INNER JOIN Orders o
    ON c.CustomerID = o.CustomerID
ORDER BY o.OrderAmount DESC;

Used in business reports, dashboards, transaction listings, and analytical outputs.

  • ORDER BY sorts the final result.
  • Joined columns can be used for sorting.
  • ASC sorts ascending.
  • DESC sorts descending.
  • Multiple sorting columns can be specified.
Can ORDER BY use a column from a joined table?

Yes. A column from a joined table can be used for sorting when it is available to the query.

What is the default ORDER BY direction?

The default sorting direction is generally ascending, represented by ASC.

Have you finished this lesson?

Introduction to SQL – All Lessons