Salesforce Dictionary - Free Salesforce GlossarySalesforce Dictionary
DictionarySSemi-Join
DevelopmentIntermediate

Semi-Join

In Salesforce SOQL, a query pattern that uses a subquery in the WHERE clause to filter parent records based on criteria in a child object, such as selecting accounts where related opportunities meet certain conditions.

§ 01

Definition

In Salesforce SOQL, a query pattern that uses a subquery in the WHERE clause to filter parent records based on criteria in a child object, such as selecting accounts where related opportunities meet certain conditions.

§ 02

In plain English

👋 Study buddy

A Semi-Join in Salesforce SOQL is a query pattern where you use a subquery in the WHERE clause to filter parent records based on criteria in a child object. Like 'give me all accounts where at least one related opportunity is over $100K.'

§ 03

Worked example

scenario · real-world use

A developer at Sallow Software needs to find all Accounts with at least one open Opportunity over $50K. Without a Semi-Join, she'd query Opportunities first, build a Set of Account IDs in Apex, then query Accounts WHERE Id IN that Set - two SOQL calls plus client-side processing. With a Semi-Join, the query is a single SOQL: SELECT Id, Name FROM Account WHERE Id IN (SELECT AccountId FROM Opportunity WHERE Amount > 50000 AND IsClosed = false). One round-trip, no Apex, executes server-side. Semi-Joins keep complex filters off Apex and out of the SOQL governor budget - a SOQL pattern every dev relearns regularly.

§ 04

Why Semi-Join matters

In Salesforce SOQL, a Semi-Join is a query pattern that uses a subquery in the WHERE clause to filter parent records based on criteria in a child object, such as selecting accounts where related opportunities meet certain conditions. The subquery returns IDs that the outer query uses for filtering, effectively joining parent and child data in a single query.

Semi-joins are an important SOQL technique for efficient data retrieval. Without them, you'd need two separate queries (one to find matching child records, another to get the parent records) and then join them in Apex code. With semi-joins, the database handles the join, which is more efficient and uses fewer SOQL queries against governor limits.

§ 05

How organizations use Semi-Join

CodeBridge

Trains developers on semi-join patterns as efficient SOQL techniques.

Quantum Labs

Uses semi-joins to reduce query counts in their Apex code.

TerraForm Tech

Treats semi-joins as standard SOQL patterns for related-object filtering.

§

Trust & references

Official documentation

Straight from the source - Salesforce's reference material on Semi-Join.

Was this entry helpful?
Help us write better definitions. Quick reactions or detailed edit suggestions.
§

🧠 Test your knowledge

Q1. What is a Semi-Join in SOQL?

Q2. Why use semi-joins?

Q3. What do they replace?

§

Discussion

Loading…

Loading discussion…