Join Example

The example for Inner, Left, and Right joins use the OPPORTUNITY and ACTIVITY tables to demonstrate each type of join. The OPPORTUNITY and ACTIVITY tables each contain the OPPORTUNITYID field. Opportunities can exist without associated activities. Activities can exist that are not related to an opportunity. Each join example uses the same opportunity and activity records to demonstrate that different types of joins result in different records being selected. The join results records are shown in a separate column in each of the three types of joins.

In the join type examples, the OPPORTUNITY and ACTIVITY tables contain the following records:

OPPORTUNITY Table ACTIVITY Table
Opportunity1

(Activity 3)

(Activity 7)

Activity 1  
Opportunity2   Activity 2  
Opportunity3   Activity 3 (Opportunity1)
Opportunity4 (Activity 4) Activity 4 (Opportunity4)
Opportunity5 (Activity 6) Activity 5  
    Activity 6 (Opportunity5)
    Activity 7 (Opportunity1)

Note the following:

  • The OPPORTUNITY table has 5 records.
  • Only opportunity records 1, 4, and 5 have activities.
  • The ACTIVITY table has 7 records.
  • Only activities 3, 4, 6, and 7 are associated with an opportunity. The specific opportunity associated is indicated in parentheses to the right of the activity.

For each of the three types of joins, see the example: