SQL Server JOINs: The Complete Guide — Syntax, Physical Operators, and a Migration-Safety Workshop
A JOIN is the single most-written clause in T-SQL and one of the least understood beyond its basic syntax. Most developers can write an INNER JOIN correctly on the first try and have no idea whether SQL Server executed it as a Nested Loops, a Merge Join, or a Hash Match, or why that choice mattered. Fewer still know that a specific, once-common join syntax was not just deprecated but is capable of silently returning the wrong answer, and was removed from the product entirely more than a decade ago.
This guide starts with that removed syntax, because the story behind it explains why the ANSI-92 JOIN syntax exists in the first place. It then covers every logical join type SQL Server supports, the APPLY operator and when it does something a JOIN genuinely cannot, the three physical join algorithms the optimizer actually chooses between at execution time, a fourth one introduced in SQL Server 2017, and the single most common reason a join that should be fast is not. Three workshop steps are built in along the way: detecting legacy join syntax before a migration, reading a real execution plan to identify which physical operator ran, and fixing the most common join performance killer while confirming the fix in the plan itself.
What this guide covers: the removed old-style outer join syntax and why it mattered beyond style; INNER, OUTER, CROSS, and self-joins; CROSS APPLY and OUTER APPLY; the physical operators (Nested Loops, Merge Join, Hash Match, Adaptive Join) and when the optimizer picks each; implicit conversions as the most common silent join performance killer; and a workshop to detect, diagnose, and fix each of these in a real environment.
- The Syntax SQL Server Removed, and Why It Mattered
- Workshop Step 1: Detect Legacy Join Syntax Before a Migration
- The Logical JOIN Types
- APPLY: Joining to a Function, Not Just a Table
- Workshop Step 2: Identify the Physical Operator in a Real Plan
- The Physical JOIN Operators
- The Most Common Join Performance Killer: Implicit Conversion
- Workshop Step 3: Fix an Implicit Conversion and Confirm the Plan Changes
- Key Takeaways
- References
1The Syntax SQL Server Removed, and Why It Mattered
Before the ANSI-92 JOIN ... ON syntax became universal, SQL Server and Sybase (its shared ancestor) supported a proprietary outer join notation: *= for a left outer join and =* for a right outer join, written directly in the WHERE clause alongside filter conditions.
-- Old-style outer join syntax, no longer usable on any current SQL Server version
SELECT c.CustomerName, o.OrderID
FROM Customers c, Orders o
WHERE c.CustomerID *= o.CustomerID;
This was deprecated starting in SQL Server 2005 and stopped executing entirely starting in SQL Server 2008, where it began raising error 4147 unless the database compatibility level was set to 80 (SQL Server 2000) or lower. Compatibility level 80 support was itself removed after SQL Server 2012. The practical result: on any SQL Server version in current use, there is no compatibility level, no trace flag, and no workaround that will run this syntax. Code containing it will not execute at all.
Why this was removed, not just discouraged: the old syntax placed the join condition in the WHERE clause alongside ordinary filters, with no syntactic way to distinguish “this row narrows the join” from “this row narrows the result.” Under specific combinations of additional WHERE predicates, this ambiguity could cause the outer join to silently collapse into a cross join or otherwise return a different result set than the equivalent ANSI-92 query, with no error and no warning. This was a correctness problem, not only a style problem, which is why Microsoft removed the capability rather than leaving it as a permanently supported legacy option.
The inner-join comma syntax, by contrast, was never removed and remains valid ANSI SQL today:
-- Still valid today; ANSI-89 table citation, inner join only
SELECT c.CustomerName, o.OrderID
FROM Customers c, Orders o
WHERE c.CustomerID = o.CustomerID;
This distinction matters because the two are frequently conflated. Comma-style inner joins are a readability and ambiguity concern (a missing WHERE clause silently produces a cross join); the old outer join operators were an outright removed feature with a documented history of returning wrong results even while they still worked. Legacy code inherited from a pre-2008 system, or migrated from Sybase, is the most likely place to find the second problem, and it is worth finding before an upgrade rather than during one.
2Workshop Step 1: Detect Legacy Join Syntax Before a Migration
Since current SQL Server versions reject the old outer join operators outright, any surviving instance of this syntax will already have failed to compile as a stored procedure, view, or function, and would surface immediately during a migration or an upgrade of the compatibility level. Finding it in advance, rather than during a cutover window, is the point of this step.
-- Scan all object definitions for old-style outer join operators
SELECT
OBJECT_SCHEMA_NAME(sm.object_id) AS SchemaName,
OBJECT_NAME(sm.object_id) AS ObjectName,
o.type_desc AS ObjectType
FROM sys.sql_modules AS sm
JOIN sys.objects AS o ON sm.object_id = o.object_id
WHERE sm.definition LIKE '%*=%'
OR sm.definition LIKE '%=*%'
ORDER BY SchemaName, ObjectName;
This is a starting point, not a final answer. The LIKE pattern will also match unrelated text, such as a comment containing a literal *= sequence or a compound assignment operator in an embedded scripting block. Every match needs a human read, not an automated rewrite. On the other hand, a clean result here does not guarantee compatibility level 90 or higher will upgrade cleanly; it only confirms this one specific legacy pattern is absent from currently stored object definitions, not from ad hoc application code that never made it into a stored object.
3The Logical JOIN Types
Every JOIN in T-SQL expresses a logical operation: what rows should appear in the result, based on how two row sets relate. SQL Server currently supports five of these directly through the FROM clause, per the ANSI-92 syntax that has been the current standard since it superseded ANSI-89.
| Join Type | Returns | Common Use |
|---|---|---|
| INNER JOIN | Only rows with a match on both sides | Default relationship enforcement; most common join type |
| LEFT OUTER JOIN | All rows from the left table, matched rows from the right, NULLs where unmatched | “Show everything from A, with B’s data if it exists” |
| RIGHT OUTER JOIN | All rows from the right table, matched rows from the left, NULLs where unmatched | Rare in practice; nearly always rewritten as a LEFT OUTER JOIN with tables reversed for readability |
| FULL OUTER JOIN | All rows from both tables, NULLs on whichever side lacks a match | Reconciliation queries; finding rows present on only one side of a comparison |
| CROSS JOIN | Every row from the left table paired with every row from the right table | Deliberate Cartesian products; generating combinations, calendar tables, test data |
A self-join is not a distinct syntactic type; it is any of the above joins where a table is joined to itself, typically to compare rows within the same table, such as finding an employee’s manager in the same Employees table.
-- Self-join: find each employee alongside their manager's name
SELECT e.EmployeeName, m.EmployeeName AS ManagerName
FROM Employees AS e
LEFT OUTER JOIN Employees AS m ON e.ManagerID = m.EmployeeID;
The NULL behavior that catches people
A common mistake with outer joins is filtering on a right-side column in the WHERE clause when the intent was to keep it in the ON clause. Moving a condition on the “outer” side of a LEFT OUTER JOIN into the WHERE clause silently converts the query back into an INNER JOIN, because WHERE evaluates after the outer join has already produced its NULL-filled rows, and most comparisons against NULL evaluate to unknown, which WHERE treats as excluded.
-- Wrong: this WHERE clause silently turns the LEFT OUTER JOIN into an INNER JOIN
SELECT c.CustomerName, o.OrderID
FROM Customers c
LEFT OUTER JOIN Orders o ON c.CustomerID = o.CustomerID
WHERE o.OrderStatus = 'Shipped'; -- excludes customers with NO orders at all
-- Correct: keep the condition in the ON clause to preserve unmatched customers
SELECT c.CustomerName, o.OrderID
FROM Customers c
LEFT OUTER JOIN Orders o ON c.CustomerID = o.CustomerID
AND o.OrderStatus = 'Shipped';
4APPLY: Joining to a Function, Not Just a Table
APPLY, introduced in SQL Server 2005, solves a problem JOIN cannot: correlating each row of an outer table expression against a table-valued function or derived table that needs a value from that same outer row as an input parameter. A standard JOIN cannot do this; attempting to reference an outer query column inside a joined derived table or function call raises an error, because the two sides of a JOIN are evaluated in separate execution contexts that cannot see each other’s columns.
| APPLY Form | Logical Equivalent | Behavior |
|---|---|---|
| CROSS APPLY | INNER JOIN | Returns a row only when the right-side expression produces at least one row for that outer row |
| OUTER APPLY | LEFT OUTER JOIN | Returns every outer row regardless of whether the right-side expression produces anything, with NULLs when it does not |
The canonical use case is a “top N per group” query, which is awkward to express with a plain JOIN but natural with APPLY:
-- Top 3 highest-paid employees per department, using a correlated table-valued function
SELECT d.DepartmentName, top3.EmployeeName, top3.Salary
FROM Departments d
CROSS APPLY (
SELECT TOP 3 e.EmployeeName, e.Salary
FROM Employees e
WHERE e.DepartmentID = d.DepartmentID
ORDER BY e.Salary DESC
) AS top3;
If every department should appear even when it has zero employees, changing CROSS APPLY to OUTER APPLY is the entire change required. Where the right-hand side genuinely does not need a value from the left-hand row, a plain JOIN remains the simpler and equally correct choice; APPLY is a tool for correlation, not a universal replacement for JOIN.
5Workshop Step 2: Identify the Physical Operator in a Real Plan
A logical JOIN and a physical join operator are different things. Writing LEFT OUTER JOIN specifies the logical result required; the optimizer separately decides, based on table statistics, row estimates, and available indexes, which physical algorithm actually produces that result at execution time. Capture an actual plan to see this decision directly.
SET STATISTICS XML ON;
SELECT o.OrderID, c.CustomerName
FROM Orders o
JOIN Customers c ON o.CustomerID = c.CustomerID
WHERE o.OrderDate >= '2026-01-01';
SET STATISTICS XML OFF;
In the graphical plan, hover over the join icon. Three details confirm which physical operator ran and why: the operator’s name and icon (Nested Loops, Merge Join, or Hash Match), the estimated vs. actual row counts on each input (a large gap here is frequently the actual root cause when the “wrong” operator was chosen), and whether a Sort operator appears immediately before a Merge Join, which indicates the inputs were not already sorted on the join key and the optimizer paid an extra cost to sort them before merging.
6The Physical JOIN Operators
SQL Server’s cost-based optimizer estimates the cost of each candidate physical algorithm using row estimates, selectivity, and index availability, then picks the cheapest. Understanding what each algorithm actually does is what makes an execution plan legible rather than just a picture with icons on it.
Nested Loops
For each row in the outer (typically smaller) input, Nested Loops searches the inner input for matches. Three variants exist: a naive nested loop scans the entire inner table for every outer row (expensive, rare in a good plan), an index nested loop uses an existing index to look up matches directly (efficient when the outer input is small), and a temporary index nested loop where the optimizer builds and later discards a temporary index specifically to support the lookup. Nested Loops with an index is typically the best choice when the outer input is small and the inner input has a supporting index; it degrades badly as the outer input grows, since the per-row lookup cost multiplies by row count.
Merge Join
Requires both inputs sorted on the join key. It reads one row from each input simultaneously and compares them; a match is returned, and because both inputs are sorted, a non-matching row can be safely discarded since nothing behind it in the sorted order could match either. This makes Merge Join extremely efficient when the sort is free (an existing index already provides it), and comparatively expensive when the optimizer must insert an explicit Sort operator first to create that ordering.
Hash Match
Builds an in-memory hash table from the smaller input (the “build” phase), then probes it with each row of the larger input (the “probe” phase). Unlike Merge Join, Hash Match does not require sorted or indexed inputs, which makes it the common fallback for joining two large, unindexed, or unsorted sets. Its cost is driven largely by whether the build-side hash table fits in the memory grant; when it does not, SQL Server spills to tempdb, which is a common and often overlooked source of join slowness that will not show up as an obvious index problem.
Adaptive Join (SQL Server 2017 and later)
A batch-mode operator, requiring the presence of a columnstore index in the query and database compatibility level 140 or higher, that defers the choice between Hash Match and Nested Loops until after the build input has actually been scanned. The optimizer compiles a threshold row count; if the actual rows flowing through the build phase fall below that threshold, execution switches to Nested Loops, and if not, it continues as a Hash Match. This exists specifically to correct for cardinality estimation errors that would otherwise lock in the wrong algorithm at compile time, before actual data volume is known. It can be disabled at the database or statement scope via DISABLE_BATCH_MODE_ADAPTIVE_JOINS without lowering compatibility level.
The practical takeaway across all four: Nested Loops rewards a small outer input with a good index on the inner side; Merge Join rewards data that is already sorted the way the join needs; Hash Match handles the general case at the cost of memory and potential tempdb spills; Adaptive Join exists because the optimizer’s own row estimates are sometimes wrong, and this operator hedges against that specific failure mode.
7The Most Common Join Performance Killer: Implicit Conversion
A join predicate comparing columns of mismatched or incompatible data types forces SQL Server to convert one side before it can evaluate the comparison. When the conversion lands on the column side rather than a literal or parameter, the optimizer can no longer treat that column as a directly seekable value; every row must be converted before it can be compared, which eliminates an index seek in favor of a scan, regardless of how well-indexed the column is.
SQL Server resolves which side gets converted using documented data type precedence rules: the lower-precedence type converts to match the higher-precedence type. A common real-world trigger is comparing a VARCHAR column against an NVARCHAR value, since NVARCHAR outranks VARCHAR in precedence, silently forcing every row of the VARCHAR column to be converted.
-- Detect implicit conversions already present in cached plans
SELECT
qp.query_plan,
st.text AS QueryText
FROM sys.dm_exec_cached_plans AS cp
CROSS APPLY sys.dm_exec_query_plan(cp.plan_handle) AS qp
CROSS APPLY sys.dm_exec_sql_text(cp.plan_handle) AS st
WHERE CAST(qp.query_plan AS NVARCHAR(MAX)) LIKE '%CONVERT_IMPLICIT%'
AND CAST(qp.query_plan AS NVARCHAR(MAX)) LIKE '%PlanAffectingConvert%';
SQL Server 2012 and later also expose a dedicated Extended Event, sqlserver.plan_affecting_convert, that fires specifically when a conversion in a compiled plan prevents a seek, which allows catching this proactively through a lightweight trace rather than only after the fact by scanning the plan cache.
8Workshop Step 3: Fix an Implicit Conversion and Confirm the Plan Changes
The fix is always to align the data types; the only decision is which side to change. If the column’s type can be corrected at the schema level, that is the durable fix. If the schema cannot be changed, an explicit conversion belongs on the literal or parameter, never left implicit on the column, since converting the (typically much smaller) parameter side instead of every row preserves the seek.
-- Before: column is VARCHAR, parameter is implicitly NVARCHAR; column gets converted, seek is lost
SELECT * FROM dbo.Accounts WHERE AccountNumber = @AccountNumber; -- @AccountNumber declared NVARCHAR
-- After: explicit conversion moved to the parameter side; index seek preserved
SELECT * FROM dbo.Accounts WHERE AccountNumber = CONVERT(VARCHAR(20), @AccountNumber);
Confirm the fix the same way the problem was found: capture SET STATISTICS XML ON again, or re-check the plan cache query from the previous section. A successful fix shows an Index Seek in place of the prior Index Scan or Table Scan, and the CONVERT_IMPLICIT warning is gone from the plan XML entirely rather than merely relocated.
9Key Takeaways
- The old
*=/=*outer join syntax is not merely deprecated, it is removed from every currently supported SQL Server version, and its historical risk was silently wrong results, not just an eventual syntax error. - Comma-style inner joins remain valid ANSI SQL today; only the old-style outer join operators were ever removed. The two are frequently and incorrectly conflated.
- Moving a condition on the outer side of a LEFT OUTER JOIN into the WHERE clause silently converts it back into an INNER JOIN, because WHERE evaluates after NULL-filled unmatched rows are already produced.
- APPLY exists specifically for correlating an outer row against a table-valued function or derived table that needs that row’s value as an input; a plain JOIN cannot do this and will error.
- The logical JOIN keyword and the physical operator that executes it are different things. Four physical operators exist: Nested Loops, Merge Join, Hash Match, and, since SQL Server 2017, Adaptive Join, which defers the Hash-vs-Loops decision until actual row counts are known.
- Implicit conversion on the column side of a join or filter predicate is a common, often invisible cause of lost index seeks. The fix is aligning data types, or explicitly converting the literal/parameter side rather than leaving the column side to convert implicitly.
The technical information in this article was verified against Microsoft documentation at the time of publication. SQL Server features, cloud service capabilities, licensing terms, and configuration requirements can change between versions and cumulative updates. Always validate implementation details against current Microsoft Learn documentation before deploying to production. References in this article link directly to the authoritative Microsoft sources.
References
- Microsoft Docs: Joins (SQL Server)
- Microsoft Docs: FROM clause plus JOIN, APPLY, PIVOT (Transact-SQL)
- Microsoft Docs: Intelligent Query Processing Details (Adaptive Joins)
- Microsoft Docs: Deprecation of old-style JOIN syntax is only a partial thing
- Microsoft Docs: Implicit Conversions (SQL Server Blog)
- SQLYARD: SQL Server Cardinality Estimation Feedback in SQL Server 2022 and 2025
- SQLYARD: How to Read SQL Server Execution Plans: A Complete Guide from Beginner to Advanced
- SQLYARD: A Beginner-to-Advanced Guide to Query Store in SQL Server
- SQLYARD: Stale Statistics and Fragmentation Thresholds — A Production Case Study in Query Plan Instability
Discover more from SQLYARD
Subscribe to get the latest posts sent to your email.


