+ Start a Discussion
RCJesseRCJesse 

help writing a query

My query writing isnt very strong. Is it possible to write a SOQL query that would find all Id's of Contracts whose Accounts had an Opportunity whose name was = 'test'?

 

 

NBlasgenNBlasgen

Think of it like this:

 

Write a SOQL query that would display the Account ID of all Opportunites whose name was 'test'.

 

SELECT AccountId FROM Opportunity WHERE Name = 'test'

 

Sadly you can't easily go up from Account to contacts.  You would then need to perform a 2nd query.

 

It's possible that one of the newer APIs might allow "IN" to be used (but I'm not aware of this):

 

SELECT Id, Name FROM Contact WHERE AccountId IN (SELECT AccountId FROM Opportunity WHERE Name = 'test')