Development questions

Write a SOQL query to fetch Accounts that have both related Contacts AND related Opportunities.

Use two semi-joins combined with AND, one against Contact and one against Opportunity.

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

Both subqueries return Account Ids, so only Accounts present in both are returned.

soqlscenariosemi-join