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
Dano BlevinsDano Blevins 

SOQL Query with related subquery on related object

We have a field on Account and on a custom object called Program that is named the same thing and I am trying to query to see which Programs have Program.Status_Internal__c that != Account.Status_Internal__c.
This is the SOQL I am trying
SELECT ID,Status_Internal__c,
(SELECT ID,Status_Internal__c FROM Program__r)
FROM Account
WERE Account.Status_Internal__c != Program__r.Status_Internal__c


This gives me two errors, one on the WHERE clause and if you remove the WHERE Clause it still gives me the following error:
ERROR at Row:2:Column:48
Didn't understand relationship 'Program__r' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names.
 
What is needed to make this QUERY work correctly?
Best Answer chosen by Dano Blevins
Raj VakatiRaj Vakati
You need to do it like this  not like JOIN in SOQL 
 
select Account__r.Id, Account__r.Status_Internal__c, RecordType.Name, Id, Status_Internal__c
from Program__c   WERE Account__r.Status_Internal__c !='Status value'

 

All Answers

Dano BlevinsDano Blevins
select Account__r.Id, Account__r.Status_Internal__c, RecordType.Name, Id, Status_Internal__c
from Program__c  


This works but also I cannot do the where clause to filter results.
Raj VakatiRaj Vakati
You need to do it like this  not like JOIN in SOQL 
 
select Account__r.Id, Account__r.Status_Internal__c, RecordType.Name, Id, Status_Internal__c
from Program__c   WERE Account__r.Status_Internal__c !='Status value'

 
This was selected as the best answer