Beginner

163. Multiple Column Sorting

Learn how to sort SQL results using more than one column.

📘 Lesson 163 of 728 ⏱ 8 min 🎯 Beginner

Multiple column sorting allows ORDER BY to sort records using several columns in a defined priority sequence.

Business reports often require a primary sort and one or more secondary sorts to organize records correctly.

Employees can first be sorted by Department and then by Salary from highest to lowest within each department.

SQL
SELECT
    EmployeeName,
    Department,
    Salary
FROM Employees
ORDER BY Department ASC, Salary DESC;

Multiple sorting is useful in employee reports, sales reports, customer lists, transaction analysis, and operational dashboards.

  • ORDER BY can use multiple columns.
  • The first column has the highest sorting priority.
  • Additional columns break ties.
  • Each column can have its own sort direction.
  • It is useful for structured reports.
Can ORDER BY contain multiple columns?

Yes. ORDER BY can sort results using multiple columns in a specified priority.

What happens when two rows have the same first sort value?

The next ORDER BY column is used to determine their relative order.

Have you finished this lesson?

Introduction to SQL – All Lessons