[SalesForce] How to do inner or sub-query for the same object in SOQL

Currently I'm facing an issue to select the value from the same object. below here i provided the query.

I'm migration java-j2ee application to a salesforce, thisbelow query works in my sql. I'm trying to do the same here in SOQL. But it doesn't works. Could somebody can help me.

 SELECT DATA1__c, TEXT__c 
     FROM PARAMETERS__c 
     WHERE ( (TYPE__c = 'ADMINISTRATEUR') 
         AND (KEY1__c LIKE 'MONTAGE%') (AND KEY2__c = '')) 
         AND (DATA1__c 
                  IN (SELECT KEY1__c 
                      FROM Parameters__c 
                      WHERE TYPE__c = 'PERE_TECHNIQUE'))

Here in the above query i need to take the value where TYPE is based on 'TECHNIQUE' where KEY1_c should be matched to DATA1_c from the outer query.

Here query is very similar to below example

 SELECT Id 
     FROM Idea 
     WHERE ((Idea.Title LIKE 'Vacation%') 
         AND (CreatedDate > YESTERDAY)  
         AND (Id IN (SELECT ParentId 
                     FROM Vote 
                     WHERE CreatedById = '005x0000000sMgYAAU'))

The only difference is here they have used IN clause with different object, in my query i'm trying to use IN clause from the same object parameters.

Kindly let me know in case of any further clarifications.

Regards,
Arun

Best Answer

The inner and outer selects should not be on the same object type when using subqueries in SFDC.So for your case you can either break the queries in two equivalent queries

Related Topic