Customers Who Have Bought

Intermediate

Customer success wants each account that has closed at least one deal, listed once, to invite to a reference programme.

Return the Name of every Account that has at least one Opportunity in stage Closed Won. Each account appears once.

Sample data

Account 4 records

Name
Acme Cloud
Bluefin Bank
Corex Labs
Delta Retail

Opportunity 5 records

NameStageNameAmountCloseDateAccount
Acme year oneClosed Won40,000today + 30 daysAcme Cloud
Acme year twoClosed Won45,000today + 30 daysAcme Cloud
Bluefin pilotProspecting15,000today + 30 daysBluefin Bank
Corex lost bidClosed Lost30,000today + 30 daysCorex Labs
Corex winClosed Won22,000today + 30 daysCorex Labs

Expected result on the sample

Name
Acme Cloud
Corex Labs

Row order does not matter. Only the columns above are compared; extra columns in your SELECT are fine.

Hints
  • Filter Account by Id IN (SELECT AccountId FROM Opportunity WHERE ...).

What this tests

A semi-join (Id IN (SELECT AccountId FROM ...)) filters parents by a condition on their children and returns each parent once. Querying the Opportunities and reading Account.Name gives one row per deal instead, so a customer with two wins shows up twice.

SOQL

Run on sample executes your query against the sample data shown on the left and displays the rows it returns. Submit checks it against the sample plus 2 hidden datasets, comparing your rows with the expected rows on each. Queries run in a real Salesforce org; the data is inserted for your run and rolled back afterwards.