Recall & Review
beginner
What does the ROW_NUMBER() function do in SQL?
It assigns a unique sequential number to each row within a result set, starting at 1 for the first row.
Click to reveal answer
intermediate
How do you reset the row numbering for each group in SQL using ROW_NUMBER()?
Use the PARTITION BY clause inside ROW_NUMBER() to restart numbering for each group.
Click to reveal answer
beginner
Write a simple SQL snippet using ROW_NUMBER() to number rows ordered by salary descending.
SELECT employee_id, salary, ROW_NUMBER() OVER (ORDER BY salary DESC) AS rank FROM employees;
Click to reveal answer
intermediate
Can ROW_NUMBER() produce ties (same number for multiple rows)? Why or why not?
No, ROW_NUMBER() always gives unique numbers even if values are the same, unlike RANK() which can produce ties.
Click to reveal answer
beginner
What happens if you omit ORDER BY in the ROW_NUMBER() OVER() clause?
The query will fail because ORDER BY is required to define the order for numbering rows.
Click to reveal answer
What does ROW_NUMBER() assign to 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 restarts the row numbering for each group in ROW_NUMBER().
If two rows have the same value in the ORDER BY column, what does ROW_NUMBER() do?
✗ Incorrect
ROW_NUMBER() always assigns unique numbers even if values are the same.
What is required inside the OVER() clause for ROW_NUMBER() to work?
✗ Incorrect
ORDER BY is required inside OVER() to define the order for ROW_NUMBER().
Which function can produce ties in numbering rows?
✗ Incorrect
RANK() can assign the same rank to rows with equal values, producing ties.
Explain how ROW_NUMBER() works and how you can restart numbering for each group.
Think about numbering rows like giving each person a unique ticket number, and restarting numbering for each team.
You got /4 concepts.
Describe the difference between ROW_NUMBER() and RANK() functions.
Consider how a race ranking might handle ties versus unique positions.
You got /4 concepts.