Brightlane's North American and UK sales team is building a regional account list for their quarterly review. The team covers customers in the United States (country = 'US'), Canada (country = 'CA'), and the United Kingdom (country = 'GB').
Write a query to return the ID, name, and country of every customer in those three territories.
Assumptions:
- The
customerstable contains every customer Brightlane has on file. - Country codes are stored as two-letter ISO codes.
Output:
- One row per qualifying customer, with columns
id,name, andcountry.
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
id,
name,
country
FROM
customers
WHERE
country IN ('US', 'CA', 'GB') The shape
IN ('US', 'CA', 'GB') is a three-value membership test — the regional account list is defined by the three ISO country codes the team covers, and the IN list mirrors that definition exactly.
Clause by clause
SELECT id, name, countryreturns the three columns the quarterly review needs: the customer identifier, the customer's name, and the country code so the team can sort the list by territory.FROM customersreads the customer table.WHERE country IN ('US', 'CA', 'GB')keeps only the rows whosecountrymatches one of the three codes in the parentheses. Customers in any other country —'AU','DE', anything else — are dropped before the result is shaped.
You practiced extending IN to a longer membership list. The shape scales without ceremony — any number of values fits inside the parentheses, and the readability gain over chained ORs grows with the list length.