1

I have the following query:

SELECT Id, Name, (select name, Phone, Email FROM Contacts) FROM Account

the table Account has a child relationship with Contacts.

this is the result of the query:

Image 1

I want to add a where clause to this query, that will filter the contacts and show me only the record of a contact who's name is "Elon Musk".

This is the child record result:

Image 2

7

Your nested query works the same way as basic queries. So you just have to add a WHERE clause inside:

SELECT Id, Name, 
    (SELECT Name, Phone, Email 
        FROM Contacts 
        WHERE 
        Name = 'Elon Musk') 
FROM Account
|improve this answer|||||
  • Oh, thanks! dumb me.. didn't even think about editing the nested query – Dana Griff Mar 27 '17 at 13:47
  • @D.Griff - Please accept answer if it was the correct one so others looking for similar issues can find answered questions..... – Eric Mar 27 '17 at 14:08

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.