+ Start a Discussion
PallavPallav 

How to fire nested query with a "In" clause?

Hi,

I am having issue firing nested query :

Select p.Description, p.Family, p.Name from Product2 p  where id In (Select Product2Id from PricebookEntry where Pricebook2Id='01s60000000A7h5AAC')

if I provide with a ":" after In then it shows invalid token and if I do not provide it gives me a error message unexpected token "select". Please show me some light on this..

thanks in anticipation of your response and help.

regards
pallav
Divya GoelDivya Goel
Hi Pallav,
follow the following procedure:
 
PricebookEntry [ ] PE = [Select Product2Id from PricebookEntry where Pricebook2Id='01s60000000A7h5AAC'];
Set<Id> SetProduct2IDs = new Set<Id>();
 
for(PricebookEntry p: PE)
{
SetProduct2IDs.add(p.Product2Id );
}
 
Now,
Select p.Description, p.Family, p.Name from Product2 p  where id In :SetProduct2IDs ;
 
Thanks,