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

1 Answer 1

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 Oct 11, 2020 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, 2020 at 1:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .