0Pricing
SQL Interview Prep · Lesson

Multi-Column Sorting and NULL Placement

ASC/DESC mixing and how NULLS FIRST/LAST differs across databases.

Why Sorting Shows Up in Interviews

Interviewers reach for ORDER BY early because it reveals whether you understand that a SQL result set is unordered by default. Without an explicit sort, the database is free to return rows in any order it likes.

A common opener is: "How do you guarantee the rows come back in a specific order?" The only correct answer is an explicit ORDER BY clause. Relying on insertion order, primary-key order, or index order is a classic junior mistake.

In this lesson you will master multi-column sorts and the tricky question of where NULL values land.

ASC and DESC Basics

ORDER BY sorts ascending (ASC) by default. You only need DESC to reverse it. The direction applies per column, not to the whole clause.

Interview tip: state that ASC is the implicit default so you do not have to write it. Many candidates wrongly think one DESC flips every column.

SELECT name, hire_date
FROM employees
ORDER BY hire_date DESC;

All lessons in this course

  1. Multi-Column Sorting and NULL Placement
  2. LIMIT, OFFSET and FETCH FIRST
  3. Returning the Top-N Rows Reliably
  4. Sorting by Expressions and Aliases
← Back to SQL Interview Prep