Search code examples
salesforcesoql

Salesforce - SOQL - Unknown error parsing query


I have 2 SOQL Queries when ran independently work great

Query 1

SELECT 
  Id, 
  Name, 
  District_Name__c 
FROM 
  Public_School_District__c 
where 
  District_Name__c = 'AL'

Query 2

SELECT 
  District_Name_Formula__c 
FROM 
  Community_Interest__c 
where 
  District_Name_Formula__c = 'AL'

When I tried joining the query

    SELECT 
  Public_School_District__c.Id, 
  Public_School_District__c.Name, 
  Public_School_District__c.District_Name__c, 
  Community_Interest__c.District_Name_Formula__c 
FROM 
  Public_School_District__c 
  INNER JOIN Community_Interest__c ON Public_School_District__c.District_Name__c = Community_Interest__c.District_Name_Formula__c 
WHERE 
  Public_School_District__c.District_Name__c = 'AL' 
  AND Community_Interest__c.District_Name_Formula__c = 'AL'

Like this it throws Unknown error parsing query what is the issue


Solution

  • There is no support for the INNER JOIN clause in SOQL. Instead, you should use the IN operator to filter the records. So something like:

    SELECT Id, Name, District_Name__c 
    FROM Public_School_District__c 
    WHERE District_Name__c = 'AL' 
      AND Id IN (SELECT Public_School_District__c 
                 FROM Community_Interest__c 
                 WHERE District_Name_Formula__c = 'AL')
    

    You can find additional information regarding SOQL comparison operators here.