Easy SELECT & filtering Free

SQL interview question: Replace NULL With COALESCE

Handle Missing Data with COALESCE

The org chart page breaks on employees with no manager: their manager_id is NULL. The frontend team needs a safe fallback.

Use COALESCE to show 'none' wherever manager_id is NULL.

Return first_name, last_name, and reports_to (the COALESCE result). Order by last_name.

Skills: COALESCE for NULL handling

Tables

employees 37 rows
  • id integer PK
  • first_name text
  • last_name text
  • email text
  • department_id integer → departments
  • salary integer
  • hire_date text
  • manager_id integer → employees
  • title text
idfirst_namelast_nameemaildepartment_idsalaryhire_datemanager_idtitle
1AliceChen[email protected]12500002015-01-15NULLCEO
2RobertMartinez[email protected]21800002016-03-20NULLCEO
3SarahJohnson[email protected]11500002017-06-101VP Engineering

Keep going