Skip to main content

Explain Nested Loops, Merge Join, and Hash Join with when each is chosen.

Mid MS SQL
Quick Answer Nested Loops: iterate outer rows, seek matching inner rows via index รขโ‚ฌโ€ best when outer set is small. Merge Join: both inputs must be pre-sorted; scan both simultaneously รขโ‚ฌโ€ fast when indexes provide sort order. Hash Match: build a hash table from smaller input, probe with larger รขโ‚ฌโ€ chosen when sorts aren't available and data is large.

Answer

Nested Loops: Best for small outer input and indexed inner table. Great for OLTP random lookups.

Merge Join: Requires sorted inputs. Very fast for large, sorted datasets.

Hash Join: Best for large, unsorted sets. Spills to TempDB if memory is insufficient.

S
SugharaIQ Editorial Team Verified Answer

This answer has been peer-reviewed by industry experts holding senior engineering roles to ensure technical accuracy and relevance for modern interview standards.

Want to bookmark, take notes, or join discussions?

Sign in to access all features and personalize your learning experience.

Sign In Create Account

Source: SugharaIQ

Ready to level up? Start Practice