From the course: Querying Microsoft SQL Server 2019
Unlock this course with a free trial
Join today to access over 25,300 courses taught by industry experts.
What is a subquery? - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2019
What is a subquery?
- [Instructor] Select queries can be used inside of other queries. When this occurs, they're called sub queries or inner queries. When the SQL Server database engine executes the query, the sub query runs first and returns values that could then be used in the outer query. Let's see how this works by creating a sub query in the select list of another query. Let's first take a look at the data that's in the SalesPerson table. This query shows me how much money each salesperson has contributed to the company's bottom line year to date. The top moneymaker is currently this salesperson with the ID of 276. If I wanted to find out how far each salesperson was away from the top position, I can find it by simply subtracting their current sales number from the sales of the person with the ID of 276. You might remember that I can place a static value in the select list and have it appear for every record. For instance…