I have a query where I have to query contacts and their cases only if case status != "Completed" or "Pending"
. But in my Parent-child query, cases are getting retrieved irrespective of the filter on status.
select id,Casedeletedcontact__c,(select id,status__c from cases1__r where status__c!='Completed' or status__c!='Pending') from contact
Am I doing anything wrong here?
Best Answer
You're using the wrong operator here. You don't want
OR
, you wantAND
.Reason being is that if status is 'Pending', it'll satisfy the
!= 'Completed'
bit and thus get returned in your subquery (true || false
=true
)When you use
AND
though, both parts need to be satisfied for the result to be true (and for the child row to be returned). Since the 'Pending' and 'Completed' statuses can only ever satisfy one of those two filters, rows with those statuses will not be included. (true && false
=false
)