0

being a new learner im unable to fetch accounts which have contacts only with this Query==> select name,(select lastname form contacts) from account<== with this getting all accounts

3

Use this query - the outer query looks for Accounts only in the set of Contacts that have an AccountId populated.

select id, name from Account where ID IN (select accountId from Contact)
2
  • Thank you so much – salesforce NT Oct 11 '20 at 0:41
  • 1
    @salesforceNT This approach (using another query in the WHERE clause) is called a "semi join" by Salesforce. There's documentation for this (comparison operators in the SOQL and SOSL reference) in case you want to dig deeper. – Derek F Oct 11 '20 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.