Sams Teach Yourself Transact-SQL in 21 Days, Second Edition
by Lowell Mauer, David Solomon, Bennett McEwan
Day 6. Using Subqueries
One of the capabilities of SQL is to nest one SQL query within another. If you want to select data from one table based on a list of values, you could enter the WHERE condition values manually using an IN clause, or you could use a second SQL SELECT statement to get the values. When you use the result set from one query to supply another query's conditions, you are using a subquery. Subqueries enable you to perform in one step what otherwise would require multiple steps. In today's lesson, you will learn
How to write subqueries
Why to use subqueries: what they do and why they're useful
Subqueries returning a single value
Subqueries returning multiply values
Using the IN clause with a subquery
Correlated subqueries
Using WHERE ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access