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.
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.
In plain English
“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.'”
Worked example
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.
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.
How organizations use Semi-Join
Trains developers on semi-join patterns as efficient SOQL techniques.
Uses semi-joins to reduce query counts in their Apex code.
Treats semi-joins as standard SOQL patterns for related-object filtering.
Trust & references
Straight from the source - Salesforce's reference material on Semi-Join.
- SOQL SELECT ExamplesSalesforce Developers
🧠 Test your knowledge
Q1. What is a Semi-Join in SOQL?
Q2. Why use semi-joins?
Q3. What do they replace?

Discussion
Loading discussion…