Brightlane's CRM team is segmenting the customer base for targeting purposes and needs to understand what country-and-activity combinations exist.
Write a query to return each unique pairing of country and active status from the customer base.
Assumptions:
- The
customerstable contains every customer Brightlane has on file. - A pairing is unique only when both values differ — "US, active" and "US, inactive" are two separate pairings; two customers who are both "US, active" collapse to one row.
Output:
- One row per unique combination, with columns
countryandis_active.
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 DISTINCT
country,
is_active
FROM
customers The shape
DISTINCT deduplicates on the whole row, not column by column. With two columns in the SELECT list, two rows are duplicates only when country matches and is_active matches. So US, active and US, inactive survive as two separate rows — they're different pairings, even though the country is the same.
Clause by clause
SELECT DISTINCT country, is_activenames the two columns the segment list needs and tells SQL to deduplicate the output. The keyword applies once, before the entire column list, and the deduplication runs across the pair. Each row of the result represents one unique combination of values across both columns at once.FROM customersis the row source. Every customer contributes their(country, is_active)pair to the candidate set; the deduplication runs across that whole set to produce one row per unique pair.
In the result, IE shows up twice (active and inactive), GB shows up twice, US shows up twice — those countries have customers in both activity states. MX, AU, KR, PL show up only once, with is_active = true, because none of their customers are inactive in this base.
Why this and not DISTINCT country, is_active reading as two separate deduplications
A common mental model error is reading DISTINCT country, is_active as "give me distinct countries and distinct active states." That would produce 22 country rows plus two activity rows, or a cross-product, or something else entirely. DISTINCT doesn't work column by column. It treats the SELECT list as a tuple and deduplicates tuples.
The operational rule: every column added to the SELECT list makes the deduplication scope wider, which almost always produces more rows, not fewer. DISTINCT country alone returned 22 rows. DISTINCT country, is_active returns 28 — the six extra rows are the countries where both activity states are present in the base.
You practiced applying DISTINCT across multiple columns at once. The recurring rule: DISTINCT operates on the whole row, so two rows match only when every column in the SELECT list matches — adding or removing a column changes which rows count as duplicates.