0
0
SQLquery~5 mins

NULL in DISTINCT, GROUP BY, and ORDER BY in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does NULL represent in SQL?
NULL means a missing or unknown value. It is not the same as zero or an empty string.
Click to reveal answer
beginner
How does DISTINCT treat NULL values in SQL?
DISTINCT treats all NULLs as the same value. So, multiple NULLs count as one distinct value.
Click to reveal answer
beginner
How does GROUP BY handle NULL values?
GROUP BY groups all rows with NULL in the same column together as one group.
Click to reveal answer
intermediate
Where do NULL values appear when using ORDER BY?
In ORDER BY, NULLs usually appear last when sorting ascending, and first when sorting descending, but this can vary by database.
Click to reveal answer
intermediate
Can NULL values affect the result count in DISTINCT or GROUP BY?
Yes, since all NULLs count as one value, they reduce the number of distinct groups or rows compared to counting each NULL separately.
Click to reveal answer
In SQL, how does DISTINCT treat multiple NULL values in a column?
ACounts all NULLs as one distinct value
BIgnores NULL values completely
CReturns an error if NULLs exist
DCounts each NULL as a separate distinct value
When using GROUP BY on a column with NULL values, what happens to those NULLs?
AEach NULL is treated as a separate group
BThey are excluded from the result
CThey are grouped together as one group
DThe query fails with an error
By default, where do NULL values appear when sorting with ORDER BY ascending?
AAt the end of the result set
BIn the middle of the result set
CAt the beginning of the result set
DThey are removed from the result set
Does GROUP BY consider NULL values equal or different?
ADepends on the database version
BDifferent, each NULL is unique
CNULLs are ignored
DEqual, all NULLs form one group
If a column has multiple NULLs, how many distinct values does DISTINCT count for those NULLs?
AZero
BOne
CThe number of NULLs
DIt depends on the query
Explain how NULL values are treated in DISTINCT, GROUP BY, and ORDER BY clauses in SQL.
Think about how SQL handles unknown or missing values in these clauses.
You got /3 concepts.
    Describe the impact of NULL values on the number of groups or distinct rows returned by SQL queries using DISTINCT or GROUP BY.
    Consider how NULLs are treated as equal or different.
    You got /2 concepts.