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 )

3
  • 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
    Commented Dec 18, 2014 at 23:28
  • I am not sure if this is possible.
    – Manju
    Commented Dec 18, 2014 at 23:28
  • I think the problem is I don't have a relationship established between the two objects.
    – user7123
    Commented Dec 18, 2014 at 23:29

1 Answer 1

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];
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .