Unreachable Dental Patients
A dental clinic is sending appointment reminders. Before the campaign, the front desk wants a list of patients they cannot reach at all: patients with no phone number and no email address on file. A missing value is stored as NULL.
Return two columns, patient_id and full_name, one row per unreachable patient, in any order. A patient who has at least one of the two contact details is reachable and must not appear. If every patient is reachable, return no rows.
Tables
patients — One row per registered patient of the clinic.
| Column | Type | Description |
|---|---|---|
patient_id (key) | INTEGER | Unique patient id |
full_name | TEXT | Patient name as written on the intake form |
phone | TEXT | Contact phone number; NULL when the patient gave none |
email | TEXT | Contact email address; NULL when the patient gave none |
registered_on | TEXT | Date the patient registered, 'YYYY-MM-DD' |
Example
patients
| patient_id | full_name | phone | registered_on | |
|---|---|---|---|---|
| 1 | Amara Osei | 555-0142 | amara@mail.test | 2025-01-09 |
| 2 | Bilal Haddad | NULL | NULL | 2025-02-14 |
| 3 | Chiara Ricci | NULL | chiara@mail.test | 2025-02-20 |
| 4 | Dmitri Volkov | 555-0177 | NULL | 2025-03-02 |
| 5 | Esi Mensah | NULL | NULL | 2025-03-15 |
| 6 | Farid Rahimi | 555-0190 | farid@mail.test | 2025-04-01 |
Expected output
| patient_id | full_name |
|---|---|
| 2 | Bilal Haddad |
| 5 | Esi Mensah |
Rows may be returned in any order. Your query also runs against hidden datasets with tricky edge cases.
SQL Path · Select & Filter · problem 7 of 70 · SQLite
The idea
SQL uses three-valued logic: a comparison is true, false or unknown. Any comparison involving NULL, including NULL = NULL, is unknown, and WHERE keeps only rows where the condition is true. That is why phone = NULL silently matches nothing.
The dedicated test is IS NULL, which returns a plain true or false. A patient is unreachable when phone IS NULL AND email IS NULL. AND is the right connective because one surviving contact detail is enough to reach someone.
The alternative uses COALESCE(phone, email), which returns the first non-NULL argument. It is NULL only when both arguments are NULL, so a single IS NULL test on it gives the same answer. It is compact and handy when you check three or four columns at once.
Solution
SELECT patient_id,
full_name
FROM patients
WHERE phone IS NULL
AND email IS NULL;
Another way
SELECT patient_id,
full_name
FROM patients
WHERE COALESCE(phone, email) IS NULL;
Why common answers fail
Comparing with = NULL is never true (it evaluates to NULL), so the query always returns no rows.
SELECT patient_id, full_name FROM patients WHERE phone = NULL AND email = NULL;
Uses OR, so patients missing only one detail (and still reachable) are listed too.
SELECT patient_id, full_name FROM patients WHERE phone IS NULL OR email IS NULL;
Looks for empty strings, but a missing value here is NULL, which is not the same as an empty string.
SELECT patient_id, full_name FROM patients WHERE phone = '' AND email = '';
What the interviewer is checking
This checks whether you know that NULL means "unknown" and needs IS NULL, a gap that causes silent empty reports in production.
Mistakes to avoid
- Writing = NULL or <> NULL, which never matches anything.
- Using OR when the business rule needs both details to be missing.
- Treating an empty string and NULL as the same thing.
Follow-ups to expect
- Also treat blank strings as missing. (NULLIF(TRIM(phone), '') IS NULL)
- Count reachable and unreachable patients in one query. (SUM(CASE WHEN ... THEN 1 ELSE 0 END))
- List patients missing exactly one of the two details. (one IS NULL, the other IS NOT NULL, via OR of two ANDs)
In real work
Data-quality checks before email or SMS campaigns, CRM hygiene reports and onboarding audits all start by finding rows with missing contact fields.