How a LATERAL JOIN solves the top-N per group problem, and its advantages over window functions
Role: Data Scientist
Category: Data Manipulation (SQL/Python)
Difficulty: medium
Interview Round: Other
Overview: Explain how a LATERAL JOIN returns the top N rows for each group in SQL and how it compares with ranking rows using ROW_NUMBER() window functions. Tests understanding of correlated subqueries, index design, query plans and the data shapes where each approach is faster.