0
0
PostgreSQLquery~10 mins

ORDER BY with NULLS FIRST and NULLS LAST in PostgreSQL - Interactive Code Practice

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

Complete the code to order the results by the column score in ascending order with NULL values appearing first.

PostgreSQL
SELECT * FROM players ORDER BY score [1];
Drag options to blanks, or click blank then click option'
ANULLS FIRST
BASC
CNULLS LAST
DDESC
Attempts:
3 left
💡 Hint
Common Mistakes
Using only ASC without NULLS FIRST will put NULLs last by default.
Using DESC instead of NULLS FIRST changes the order direction.
2fill in blank
medium

Complete the code to order the results by the column date_joined in descending order with NULL values appearing last.

PostgreSQL
SELECT * FROM members ORDER BY date_joined [1];
Drag options to blanks, or click blank then click option'
ANULLS FIRST
BNULLS LAST
CDESC NULLS LAST
DDESC
Attempts:
3 left
💡 Hint
Common Mistakes
Using only DESC puts NULLs first by default.
Using NULLS FIRST will put NULLs at the beginning, which is not desired here.
3fill in blank
hard

Fix the error in the code to order by price ascending with NULL values last.

PostgreSQL
SELECT * FROM products ORDER BY price [1];
Drag options to blanks, or click blank then click option'
AASC NULLS FIRST
BNULLS LAST
CDESC NULLS LAST
DASC NULLS LAST
Attempts:
3 left
💡 Hint
Common Mistakes
Using only NULLS LAST without ASC or DESC causes syntax error.
Using DESC NULLS LAST changes the order direction.
4fill in blank
hard

Fill both blanks to order by rating descending with NULL values first.

PostgreSQL
SELECT * FROM reviews ORDER BY rating [1] [2];
Drag options to blanks, or click blank then click option'
ADESC
BNULLS FIRST
CASC
DNULLS LAST
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the order direction and NULLS clause.
Using NULLS LAST when NULLS FIRST is required.
5fill in blank
hard

Fill all three blanks to order by score ascending with NULL values last, then by name descending with NULL values first.

PostgreSQL
SELECT * FROM leaderboard ORDER BY score [1] [2], name [3];
Drag options to blanks, or click blank then click option'
AASC
BNULLS LAST
CDESC NULLS FIRST
DDESC
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to specify NULLS position for one or both columns.
Mixing up ASC and DESC directions.