You need to sign in to do that
Don't have an account?

Why do I get different results from SOQL in Query Editor than when run as anonymous apex code?
SOQL Query:
Select (Select product2.Name From OpportunityLineItems) From Opportunity
Where Id IN
(Select OpportunityId from opportunityLineItem where Name like '%LS00425%')
Returns: [{"Product2":{"attributes":{"type":"Product2","url":"/services/data/v48.0/sobjects/Product2/01t1I000004O9fMQAS"},"Name":"STE9923"}},{"Product2":{"attributes":{"type":"Product2","url":"/services/data/v48.0/sobjects/Product2/01t1I000004OzGwQAK"},"Name":"LS00425"}}]
Apex Query:
List<Opportunity> myOpportunity = [Select (Select product2.Name From OpportunityLineItems) From Opportunity
Where Id IN
(Select OpportunityId from opportunityLineItem where Name like '%LS00425%')];
Returns:
(Opportunity:{Id=0061I00000JT2c5QAD, RecordTypeId=0121I000000NvQqQAK})
Select (Select product2.Name From OpportunityLineItems) From Opportunity
Where Id IN
(Select OpportunityId from opportunityLineItem where Name like '%LS00425%')
Returns: [{"Product2":{"attributes":{"type":"Product2","url":"/services/data/v48.0/sobjects/Product2/01t1I000004O9fMQAS"},"Name":"STE9923"}},{"Product2":{"attributes":{"type":"Product2","url":"/services/data/v48.0/sobjects/Product2/01t1I000004OzGwQAK"},"Name":"LS00425"}}]
Apex Query:
List<Opportunity> myOpportunity = [Select (Select product2.Name From OpportunityLineItems) From Opportunity
Where Id IN
(Select OpportunityId from opportunityLineItem where Name like '%LS00425%')];
Returns:
(Opportunity:{Id=0061I00000JT2c5QAD, RecordTypeId=0121I000000NvQqQAK})
Your query is answered in the below blogs,
https://salesforce.stackexchange.com/questions/85948/soql-execute-anonymous-and-query-editor-returning-different-results
https://salesforce.stackexchange.com/questions/161886/different-results-for-same-query-in-anonymous-execute-and-regular-class-executio
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks.