Brightlane's email marketing team is running a location-targeted campaign and needs to reach only deliverable, active accounts.
Write a query to return the name and email of every active US customer who has a city on file.
Assumptions:
- US customers are identified by
country = 'US'. - Active customers are identified by
is_active = true. - Some rows have a recorded
cityvalue; others havecityset toNULL. A customer withcityset toNULLis considered to have no deliverable address.
Output:
- One row per qualifying customer, with columns
nameandemail.
Schema · ecommerce 5 tables
Run previews · Check grades
Write a query, then run it to see results here.
Worked solution Try it yourself first
SELECT
name,
email
FROM
customers
WHERE
country = 'US'
AND is_active = TRUE
AND city IS NOT NULL The shape
Three requirements joined by AND — country, active flag, and a non-null city all have to hold on the same row before it lands in the deliverable audience.
Clause by clause
SELECT name, emailreturns the two columns the email campaign needs.FROM customersreads the customer table; the filter narrows from there.WHERE country = 'US' AND is_active = true AND city IS NOT NULLchains three conditions.country = 'US'keeps US rows.is_active = truekeeps active rows.city IS NOT NULLkeeps rows where the city is on file. EveryANDraises the bar — a row drops out the moment any single condition fails, regardless of whether the others passed.
Why IS NOT NULL and not city <> ''
A missing city is stored as NULL, not as an empty string. city <> '' compares against the empty string, and against NULL the comparison returns unknown — which WHERE drops. The NULL-city rows would slip through the filter, and the campaign would attempt delivery to an empty address. IS NOT NULL is the only operator that directly tests for the presence of a value, and it always returns true or false.
You practiced chaining three conditions with AND. The pattern scales without ceremony — each new requirement is one more condition joined by AND, and the row must satisfy every one to pass.