SOQL Joins

Let’s look at what we can do with this data with some familiar JOIN patterns borrowed from SQL. This time, however, we will utilize them in SOQL and also use the power of relationship traversal in path expressions that allow us to do joins implicitly. In each case below, we will use the pattern with respect to a query problem that we would like to express with SOQL.
For Position, we will use Position__c ,
for Application we will use Job_Application__c ,
and for Candidate we will use Candidate__c
in the corresponding code snippets.

Right, Outer Join Problem:

Find job Applications and related Departments (from Applications). Note that for this example, we would like to list applications including those which are not related to a Position yet. This is accomplished by an

outer join.

[php]SOQL Query: SELECT Name, Position__r.Functional_Area__c FROM Job_Application__c[/php]

RESULT

Left Inner Joi

Problem: Find names of all positions for which there are associated applications

SOQL:

[php]SELECT Name FROM Position_c WHERE Id IN
(SELECT Position__c FROM Job_Application__c)[/php]

RESULT

 

Right Inner Join

Problem: Find all applications for positions that are in the ‘Sales’ department.

SOQL:

[php]SELECT Name,Position__r.Name,
FROM Job_Application__c
WHERE Position__r.Functional_Area__c= ‘Sales’[/php]

===================

[php]SELECT Name,Position__r.Name, Position__r.Functional_Area__c
FROM Job_Application__c WHERE Position__r.Functional_Area__c=’Human Resource'[/php]