Chapter 7. TOP and APPLY

This chapter covers two query elements that might seem unrelated to each other. One element is the TOP option, which allows you to limit the number of rows affected by a query. The other is the new APPLY table operator, which allows you to apply a table expression to each row of another table expression—basically creating a correlated join. I decided to cover both in the same chapter because I find that quite often you can use them together to solve querying problems.

I’ll first describe the fundamentals of TOP and APPLY, and then follow with solutions to common problems using these elements.

Get Inside Microsoft® SQL Server™ 2005: T-SQL Querying now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.