# How would you list Contact-only Accounts, meaning Accounts with Contacts but zero Opportunities, using one SOQL query?

**Topic:** Development · **Difficulty:** Medium · **Asked at:** Cognizant, Deloitte, EY · **Tags:** soql, scenario, semi-join, anti-join

Read it on the site: https://www.forcechallenges.com/interview-questions/how-would-you-list-contact-only-accounts-meaning-accounts-with-contacts-but-zero-opportunities-using-one-soql

## Answer

Pair a semi-join on Contact with an anti-join on Opportunity in the same WHERE clause. This finds Contact-only Accounts: those with at least one Contact and zero Opportunities.

```soql
SELECT Id, Name FROM Account
WHERE Id IN (SELECT AccountId FROM Contact)
  AND Id NOT IN (SELECT AccountId FROM Opportunity)
```

---
Source: ForceChallenges · last updated 2026-10-19
