Brightlane's marketing team is preparing a domestic email campaign for the upcoming product launch and needs a list of US-based customers to target.
Write a query to return the name and email of every customer registered in the United States.
Assumptions:
- The
customerstable contains every customer Brightlane has on file. - The
countrycolumn records the customer's country of registration as a two-letter code; US-registered customers havecountryset to'US'.
Output:
- One row per US-registered 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' The shape
The equality check on country decides which rows survive, and the SELECT list controls what comes back for each one. Filter first, shape second.
Clause by clause
SELECT name, emailnames two columns from thecustomerstable — exactly what the marketing email campaign needs, nothing more. The columns come back in the order they're listed.FROM customersis the source: every customer Brightlane has on file, withcountryrecorded as a two-letter code.WHERE country = 'US'keeps only the rows whosecountryvalue is the literal'US'. PostgreSQL checks each row'scountryagainst the literal once, in isolation, and either keeps the row or drops it beforeSELECTever sees it.
The trap
String comparisons in PostgreSQL are case-sensitive and whitespace-sensitive. WHERE country = 'US' matches 'US' exactly; it does not match 'us', 'Us', or 'US ' with a trailing space. Whenever the values in a column may have been entered inconsistently, an exact-match filter will silently miss the ones that don't match the spelling you wrote.
You practiced filtering rows by an exact-match condition on a single column. The WHERE column = 'value' shape is how every constant-filter query starts.