Ranking

Learn how to rank rows using SQL.

Overview

Ranking is an extremely common task. Ranking employees by performance, products by popularity, or students by score, are all different ways to use ranking.

Row numbers

The most basic form of ranking is adding a row number to each row. In PostgreSQL, we can add row numbers in a specific sort order using the ROW_NUMBER window function:

Get hands-on with 1400+ tech skills courses.