0
0
SQLquery~10 mins

NULL in DISTINCT, GROUP BY, and ORDER BY in SQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the SQL query to select unique values including NULLs from the column 'category'.

SQL
SELECT DISTINCT [1] FROM products;
Drag options to blanks, or click blank then click option'
Acategory
Bcategory IS NOT NULL
CCOUNT(category)
D*
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' with DISTINCT returns unique rows, not unique values of a single column.
Using COUNT(category) returns a count, not distinct values.
Using 'category IS NOT NULL' is a condition, not a column name.
2fill in blank
medium

Complete the SQL query to group rows by the 'status' column, including NULL values as a group.

SQL
SELECT status, COUNT(*) FROM orders GROUP BY [1];
Drag options to blanks, or click blank then click option'
Astatus IS NOT NULL
BCOUNT(status)
Cstatus
DDISTINCT status
Attempts:
3 left
💡 Hint
Common Mistakes
Using COUNT(status) in GROUP BY causes syntax error.
Using 'status IS NOT NULL' is a condition, not a grouping column.
Using DISTINCT status is invalid in GROUP BY clause.
3fill in blank
hard

Fix the error in the ORDER BY clause to sort by 'price' including NULL values last.

SQL
SELECT * FROM products ORDER BY price [1];
Drag options to blanks, or click blank then click option'
ADESC
BASC NULLS LAST
CDESC NULLS FIRST
DASC
Attempts:
3 left
💡 Hint
Common Mistakes
Using DESC sorts descending, not ascending.
Using NULLS FIRST places NULLs before numbers.
Omitting NULLS LAST places NULLs first by default in some databases.
4fill in blank
hard

Fill both blanks to select unique 'department' values and order them with NULLs first.

SQL
SELECT DISTINCT [1] FROM employees ORDER BY [2] NULLS FIRST;
Drag options to blanks, or click blank then click option'
Adepartment
Bsalary
Demployee_id
Attempts:
3 left
💡 Hint
Common Mistakes
Ordering by a different column than selected causes confusing results.
Using salary or employee_id does not match the selected column.
Omitting NULLS FIRST places NULLs last by default.
5fill in blank
hard

Fill all three blanks to group by 'region', count orders, and order groups with NULL regions last.

SQL
SELECT [1], COUNT(*) FROM sales GROUP BY [2] ORDER BY [3] NULLS LAST;
Drag options to blanks, or click blank then click option'
Aregion
Dorder_date
Attempts:
3 left
💡 Hint
Common Mistakes
Using different columns for select, group by, and order by causes errors or confusing results.
Ordering by order_date does not match grouping by region.
Omitting NULLS LAST places NULLs first by default in some systems.