From the course: Microsoft SQL Server 2016: Query Data

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Writing subqueries

Writing subqueries - SQL Server Tutorial

From the course: Microsoft SQL Server 2016: Query Data

Start my 1-month free trial

Writing subqueries

- [Voiceover] In this lesson, we're going to take a look at writing subqueries in Transact-SQL. Now, a subquery is simply one query that exists within another query, so we're nesting select statements, is what we're doing. It's good to take a look at examples, because it really helps us better understand these. Our first subquery, we're going to return a single value and these are really the simplest that you'll write. Returning a single value that becomes usable in the outer query. Again, we have to stop and think about how these queries are going to execute, so we can understand how we're returning information from the inner query to be utilized in the outer query. Let's look at this first one and just decipher it before we actually run the query itself to see what's taking place. In the first query, we're saying that we want order quantity and line total. We're going to pull it out of the sales order detail table. We have our where clause here, so we're going to be looking for a…

Contents