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

1 Answer 1

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
2
  • Oh, thanks! dumb me.. didn't even think about editing the nested query
    – Dana Griff
    Mar 27, 2017 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, 2017 at 14:08

You must log in to answer this question.

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