SQL QuestSQL Interview Questions › NULL Handling

Handling NULL Values

EasyFreeQuerying BasicsNULL Handling

NULL means 'unknown', not zero. Find passengers whose age is NULL (unknown). Show name, pclass, fare, and a column called age_display that shows 'Unknown' when age is NULL, or the age value when it's known. Sort by fare descending. Limit to 15 rows.

Solve it in the browser editor →

Runs on SQLite in your browser, graded against the expected result, no signup. A wrong answer gets a diagnosis, not just "incorrect".

Schema

passengers

passenger_idsurvivedpclassnamesexagesibspparchfareembarked
103Braund, Mr. Owen Harrismale22107.25S
211Cumings, Mrs. John Bradleyfemale381071.28C
313Heikkinen, Miss. Lainafemale26007.93S

Expected output: age_display shows 'Unknown'

Hint

WHERE age IS NULL finds NULLs (not age = NULL, which never works!). COALESCE(age, 'Unknown') returns 'Unknown' when age is NULL.

Concepts

SELECT IS NULL COALESCE NULL Handling

Practise the topic: SQL practice questions · NULL handling practice

Related questions

Default Age for Missing Records (COALESCE)Easy · FreeLEFT JOIN: Watch the NULLs AppearEasy · FreeFailures with No Loss EstimateEasy · FreeProperties Without Listed OwnerEasy · FreeChargeback Reason Codes: Resolved and Still OpenEasy · FreeGenre Box Office ReportMedium · Free

Where would this cost you points in an interview?

Ten questions, no signup: a Skillmap across nine SQL skills and the one to fix first.

Take the readiness test