Browse SQL Topics ▼

NULL Ordering (NULLS FIRST / LAST)

📂 Sorting & Pagination 📘 Lesson 31 of 81

Dictate whether missing values appear at the beginning or end of sorted results using NULLS FIRST and NULLS LAST.

NULL Ordering (NULLS FIRST / LAST) is an essential topic in SQL and relational database engineering.

Overview

Building on foundational principles introduced in multi-column-sorting, mastering null ordering (nulls first / last) provides the core mental model and practical query skills needed for production relational database engineering.

-- Place missing ratings at the very end regardless of DESC
SELECT title, rating
FROM movies
ORDER BY rating DESC NULLS LAST;

Key Concepts

  • Understand the fundamental syntax, conventions, and mental model.
  • Avoid common beginner traps, data type mismatches, and performance pitfalls.
  • Apply practical idioms directly in production applications.

[!TIP] Master this concept to build a rock-solid foundation. Next, proceed to limit-offset.

Test your understanding of NULL Ordering (NULLS FIRST / LAST)

Quick interactive practice questions with instant feedback.

Take Quiz →