Recall & Review
beginner
What does the ROW_NUMBER() window function do in SQL?
ROW_NUMBER() assigns a unique sequential number to each row within a partition of a result set, starting at 1 for the first row.
Click to reveal answer
beginner
How do you reset the row numbering for each group in a table using ROW_NUMBER()?
Use the PARTITION BY clause inside the OVER() clause to restart numbering for each group.
Click to reveal answer
intermediate
Write a simple SQL query using ROW_NUMBER() to number employees ordered by their salary descending.
SELECT employee_id, salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS rank FROM employees;
Click to reveal answer
beginner
Can ROW_NUMBER() be used without PARTITION BY? What happens then?
Yes, if PARTITION BY is omitted, ROW_NUMBER() numbers all rows in the entire result set sequentially.
Click to reveal answer
intermediate
Why is ROW_NUMBER() useful compared to using LIMIT or OFFSET for pagination?
ROW_NUMBER() allows numbering rows in a stable order and can be combined with filtering to implement efficient pagination without skipping rows.
Click to reveal answer
What does ROW_NUMBER() return for each row?
✗ Incorrect
ROW_NUMBER() assigns a unique sequential number to each row starting at 1.
Which clause is used with ROW_NUMBER() to restart numbering for each group?
✗ Incorrect
PARTITION BY divides rows into groups and restarts ROW_NUMBER() for each group.
What happens if you omit PARTITION BY in ROW_NUMBER()?
✗ Incorrect
Without PARTITION BY, ROW_NUMBER() numbers all rows sequentially in the full result set.
How can ROW_NUMBER() help with pagination?
✗ Incorrect
ROW_NUMBER() numbers rows so you can select a range for a page, like rows 11 to 20.
Which of these is a valid ROW_NUMBER() usage?
✗ Incorrect
ROW_NUMBER() requires OVER() with optional PARTITION BY and ORDER BY clauses.
Explain how ROW_NUMBER() works and how you can use PARTITION BY with it.
Think about numbering rows within groups like pages in a book.
You got /4 concepts.
Describe a real-life scenario where ROW_NUMBER() can help solve a problem.
Imagine you want to show top salespeople per region.
You got /4 concepts.