Conclusion

This chapter covered subqueries. It discussed self-contained subqueries, which are independent of the outer query, and correlated subqueries, which are dependent on the outer query. Regarding the result of the subquery, I discussed scalar and multi-valued subqueries. I also provided a more advanced section as optional reading in which I covered returning previous and next values, running aggregates, and misbehaving subqueries.

Remember to always think about the three-valued logic and the importance of prefixing column names in subqueries with the source table alias.

The next chapter focuses on table subqueries, also known as table expressions.

Get Microsoft® SQL Server® 2008 T-SQL Fundamentals now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.