function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
JBerryJBerry 

select field from table where Id IN select id from different table

Hi,

I am trying to do a SQL query, where my where clause is based on another SQL query.  I want to do something like:

select ListPrice from OpportunityLineItem where OpportunityId IN (select Id from Opportunity where Status='Closed')

Does anyone know how to go about this?

Thanks!
SuperfellSuperfell
You can use SOQL-R to do that sort of query without the use of In or a subsuery.

Select listPrice from OpportunityLineItem where Opportiunity.Status = 'closed'
JBerryJBerry
Okay, bad example =).

Say i have a date range of March 20 - March 31st.  I want to get all the opportunities within that date range.  From there, I get the account id's of those opportunities.

After that, I get the ListPrice for a particular line item, for each opportunity that belongs to one of the original owners(accounts).

Basically, we want to see how much the owner(account) of the opportuntiy in that time range has spent with us so far that month.
SuperfellSuperfell
There are no subqueries, there is soql-r which provides some of those kinds of queries, but in a more OO kind of manner. check the docs.