From the course: Querying Microsoft SQL Server 2022

Unlock the full course today

Join today to access over 24,200 courses taught by industry experts.

Correlated subqueries

Correlated subqueries

- [Instructor] Subqueries can be used in place of JOIN statements in a query as an alternate way of reviewing related information that's spread across multiple tables. For instance, I can write out two queries that looks at the people and employees in the AdventureWorks database. (keyboard clicking) Executing both queries at the same time will give me these results, here at the bottom of the screen. Now both of these tables are related on the BusinessEntityID column. In the Person.Person table, here at the top, I can find the First and Last Names of all of our people, and in the HumanResources.Employee table here at the bottom, I can find the job titles for those people that actually are employees. Now, if I wanted to view all of these details together I might use an INNER JOIN in the FROM clause of a query. Let me go ahead and minimize this and we'll make that change here in the top. First, we'll select a couple of…

Contents