1

I need help with this SOQL statement. I need it to return results from Account object based on a subquery. What I have below doesn't work. The objects are 1:1 relationship. There is an External ID on Business__c and Account object.

Thanks,

SELECT ID, Combine__c FROM Account WHERE Combine__c IN ( SELECT ID, Combine__c FROM Business__c )

  • Thanks Daniel, but that will not work. Error Message: The left operand field in the where expression for outer query should be an id field, cannot use: 'Combine__c'. – user7123 Dec 18 '14 at 23:28
  • I am not sure if this is possible. – Manjunath Nimbal Dec 18 '14 at 23:28
  • I think the problem is I don't have a relationship established between the two objects. – user7123 Dec 18 '14 at 23:29
0

I think you will need to split it into to SOQL queries or add a relationship field.

Set<string> combineIds = new Set<string>();
for(Business__c bus : [Select Combine__c from Business__c]) {
    combineIds.add(bus.Combine__c);
}
List<Account> accounts = [SELECT ID, Combine__c FROM Account WHERE Combine__c IN :combineIds];

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.