Learn with Abdou

INTERACTIVE LECTURES

SQL functions & delivery evidence

Guided class activity · apply the ideas from the full SQL lessons.

Preparing for Lab 4 · After practice, try the team challenge.

Opening your saved work…

Sign in to save across devices → · Download your guest work before switching accounts.

Keep missing values honest

Step 6 of 7 · Database: North Shore Deliveries

READ & UNDERSTAND

In packages, a NULL from_address_id means no sender is on file. It does not mean address 0, the destination, or proof that the sender deliberately hid their identity. Use IS NULL to select these records; equality to NULL does not return true.

COALESCE returns the first non-NULL value; IFNULL is the two-argument alternative. For a readable report, 'Sender #' || from_address_id becomes NULL when the sender is missing. Wrap the entire label expression in COALESCE to provide a readable fallback without changing the original ID.

An empty string and an all-space string are not NULL. COALESCE('', 'Unknown') keeps the empty string. For a text-import cleanup rule, NULLIF(TRIM(value), '') can turn an empty cleaned string into NULL before applying COALESCE. Use that rule only when a blank really means missing in your data contract.

Worked example
SELECT COALESCE('', 'Unknown') AS empty_kept, COALESCE(NULLIF(TRIM('   '), ''), 'Unknown') AS blank_label, IFNULL(NULL, 'Unknown') AS null_label;

The three expressions distinguish an empty string, spaces transformed into NULL, and an existing NULL. They need different tests.

The practice leaves the relationship column intact. A readable fallback must not invent a relationship to address 0.

Your question

For packages with id >= 34, return id, from_address_id, and COALESCE('Sender #' || from_address_id, 'Sender unknown') AS sender_label. Order by id.

Explain your evidence

Why should Sender unknown remain a report label instead of being written into an integer address field?

Try a query to unlock the worked-answer discussion.

Loading…
Table & column names only · ↑ ↓ choose · Tab insert · Esc dismiss

CURRENT DATABASE

Quick schema · North Shore Deliveries

Press Esc or click outside to return to your query. PK = primary key · FK = declared foreign key.

This database has no tables yet. Create a table, then reopen the schema to see its columns.

Control Space also opens names. Enter adds a new line. Control or Command Enter runs your query.

Query results

Predict the result, then run your query.

Predict the result, then run your query.

Read-only activity · One statement per run · First 200 rows displayed · Checks compare the complete bounded result, not just this preview.

Explore this query freely in the playground ↗

Check the save status above. Account-saved work is available in My Progress. Explanations are for discussion, not automatically graded. No prerequisite locks.