I want to query objects which are in a master-detail relationship.
(The query should work without Apex code)
The query should return only masters with child records not older than 30 days,
or masters with no child records at all.
What came to my mind is:

    (SELECT xxx__campaign__c FROM xxx__child__c WHERE SystemModStamp <= LAST_N_DAYS:30)
OR Id NOT IN (select xxx__campaign__c FROM xxx__child__c)

But since Semi join sub-selects are not allowed with the 'OR' operator this will unfortunately not work.
Is there a way to do this query, or do I have to split this into two separate queries?
Any suggestions will be highly appreciated.


If it is a master detail relationship, I would suggest to create a field if you can on the master to count no of records. And then you can use the field in your inner query to check if the master record have any children records associated with them.

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.