Recall & Review
beginner
What does the ORDER BY clause do in SQL?
It sorts the rows returned by a query based on one or more columns, either in ascending (ASC) or descending (DESC) order.
Click to reveal answer
beginner
How are NULL values treated by default when using ORDER BY in SQL?
By default, NULL values are treated as the lowest possible values and appear first when sorting in ascending order, and last when sorting in descending order.
Click to reveal answer
intermediate
What keywords can you use to control the position of NULL values in ORDER BY?
You can use NULLS FIRST or NULLS LAST to explicitly specify whether NULL values appear at the beginning or end of the sorted result.
Click to reveal answer
intermediate
Write a simple SQL query to order a table named 'employees' by the 'salary' column with NULL salaries appearing last.
SELECT * FROM employees ORDER BY salary ASC NULLS LAST;
Click to reveal answer
beginner
Why might controlling NULL ordering be important in real-life data sorting?
Because NULLs represent missing or unknown data, controlling their position helps make reports clearer and ensures important data is prioritized in the sorted list.
Click to reveal answer
By default, where do NULL values appear when you ORDER BY a column in ascending order?
✗ Incorrect
By default, NULL values are treated as the lowest values and appear first in ascending order.
Which clause explicitly places NULL values at the end of the sorted results?
✗ Incorrect
NULLS LAST forces NULL values to appear at the end of the sorted list.
What happens to NULL values when you ORDER BY a column in descending order without specifying NULLS FIRST or LAST?
✗ Incorrect
By default, NULLs appear last in descending order.
Which SQL keyword is NOT used to control NULL ordering?
✗ Incorrect
NULLS MIDDLE is not a valid SQL keyword.
If you want NULL values to appear at the top when sorting descending, which clause should you use?
✗ Incorrect
NULLS FIRST places NULL values at the beginning, even in descending order.
Explain how NULL values are ordered by default in SQL when using ORDER BY with ascending and descending sorts.
Think about how missing data is treated compared to actual values.
You got /3 concepts.
Describe how you can control the position of NULL values in an ORDER BY clause and why this might be useful.
Consider how reports or lists look when missing data is shown first or last.
You got /3 concepts.