# Merge Join: Efficiency with Ordered Data
> [!Note]
> `Merge Join achieves high throughput by performing a **parallel scan** of two **ordered** inputs, comparing keys on the fly and merging matches without per‐row lookups, provided both streams are sorted or a **Sort** operator is introduced.`
Merge Join requires that both inputs be sorted on the join key, so SQL Server will automatically inject a **Sort** operator if needed. Once ordering is guaranteed, the operator reads both data streams in tandem, advancing pointers and combining rows whose key values align. This **parallel reading** strategy makes Merge Join markedly more efficient than row‐by‐row methods like Nested Loops when working with large, pre‐ordered datasets.
The primary advantage of Merge Join lies in its ability to avoid random I/O or hash table maintenance; by capitalizing on existing sort order, it merges inputs with a linear pass. However, the cost of enforcing order on unsorted sources can significantly affect overall query performance. Thus, Merge Join is ideal when sorted indexes already exist or when the overhead of sorting is outweighed by the benefits of a single‐pass merge.
---
## ## References
- Korotkevitch, D. (2022). _SQL Server advanced troubleshooting and performance tuning: Best practices and techniques_. O’Reilly Media.
- Nevarez, B. (2022). _SQL Server query tuning and optimization: Optimize Microsoft SQL Server 2022 queries and applications_. Packt Publishing.