0
0
SQLquery~5 mins

ORDER BY with NULL values behavior in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
ARandomly
BAt the end
CAt the beginning
DIn the middle
Which clause explicitly places NULL values at the end of the sorted results?
ANULLS LAST
BNULLS FIRST
CORDER BY NULL
DIS NULL
What happens to NULL values when you ORDER BY a column in descending order without specifying NULLS FIRST or LAST?
ANULLs appear first
BNULLs appear last
CNULLs are ignored
DQuery fails
Which SQL keyword is NOT used to control NULL ordering?
ANULLS MIDDLE
BNULLS LAST
CNULLS FIRST
DORDER BY
If you want NULL values to appear at the top when sorting descending, which clause should you use?
AORDER BY DESC NULLS LAST
BNULLS LAST
CORDER BY ASC NULLS FIRST
DNULLS FIRST
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.