Accounts With No Contacts
Intermediate SolvedBefore a renewal push, account managers need to know which accounts have nobody on file to talk to.
Return the Name of every Account that has no Contacts.
Sample data
Account 4 records
| Name |
|---|
| Acme Cloud |
| Bluefin Bank |
| Corex Labs |
| Delta Retail |
Contact 3 records
| LastName | Account |
|---|---|
| Rao | Acme Cloud |
| Singh | Corex Labs |
| Patel | Corex Labs |
Expected result on the sample
| Name |
|---|
| Bluefin Bank |
| Delta Retail |
Row order does not matter. Only the columns above are compared; extra columns in your SELECT are fine.
Hints
- Use
Id NOT IN (SELECT AccountId FROM Contact).
What this tests
An anti-join (Id NOT IN (SELECT AccountId FROM Contact)) finds parents with no matching children in one query. The Apex alternative, loading every account and every contact and comparing sets, burns query rows and heap on exactly the data you want to exclude.
Datasets
Solved on this device only. Sign in with Google to keep your progress across devices.
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.