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
jojoforcejojoforce 

SOQL simple outer join? Multiple Semi-Join

Hi.....

 

I have a Parent object that have two child objects. Its a lookup type of relationship. A parent record may or may not have a record in Child A nor Child B.

 

So basically, in regular SQL I am trying to achieve something like:

 

SELECT count(id)
FROM Parent
WHERE id in (SELECT parentID from ChildA) 
OR    id in (SELECT parentID from ChildB)

 

However, this does not seem possible in SOQL statements. Is there any work around to this dilemna? I'm trying to get the Parent records if they have child records that exists in either Child A or Child B object. A parent record may have records in Child A, but not have records in Child B (and vice-versa). At the same time, a parent record may have both records in Child A and Child B.

 

Thanks for any ideas or inputs in this matter. It seems pretty easy and I'm sure a lot of people had experienced this issue. 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
jojoforcejojoforce

Yeah I was thinking of doing the same thing. I don't think its possible to just use SOQL, but I ask it anyways incase someone else knows if its possible.

All Answers

dmchengdmcheng

I don't think you can do this in one query.  You will probably have to create two maps from separate queries, then combine the Parent ID keys into a set.

jojoforcejojoforce

Yeah I was thinking of doing the same thing. I don't think its possible to just use SOQL, but I ask it anyways incase someone else knows if its possible.

This was selected as the best answer