1

I am attempting to write a query on an object, Opportunity, this object has a child object Quotes.

In Quotes where have a field named, Order_Ready.

What I need to do is filter in all opportunities that have approved quotes (Order_Ready__c == true).

Here is the query I have been attempting to get working,

SELECT Id, Name (SELECT Order_Ready__c FROM Quotes) FROM Opportunity WHERE Opportunity.Quotes.Order_Ready__c = true

I have tried a few variations of this,

SELECT Id, Name (SELECT Order_Ready__c FROM Quotes) FROM Opportunity WHERE Quotes.Order_Ready__c = true

SELECT Id, Name (SELECT Order_Ready__c FROM Quotes) FROM Opportunity WHERE Order_Ready__c = true

I have to admit, I'm not the strongest with SQL/SOQL. Any insight into where my mistake or misunderstanding might be?

Thanks!

Bryan Harrington
  • 991
  • 2
  • 17
  • 31

1 Answers1

4
SELECT Id, Name FROM Opportunity WHERE Id IN 
(Select OpportunityId FROM Quote WHERE Order_Ready__c = true)
Jeremy Ross
  • 11,544
  • 3
  • 36
  • 36
  • Thanks a bunch! When I performed a Google search on accessing Child Object fields in the WHERE clause I stumbled on this (although modified for my purpose), SELECT Id, Name (SELECT Order_Ready__c FROM Quotes) FROM Opportunity WHERE Opportunity.Quotes.Order_Ready__c = true, While Force Explorer doesn't not like this, Under what scenario would this work? The logic **seems** correct from the examples I found. – Bryan Harrington Nov 30 '11 at 22:25