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 - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2022
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
(Locked)
What is a subquery?5m 14s
-
(Locked)
Use a subquery in a HAVING clause6m 26s
-
(Locked)
Correlated subqueries6m 29s
-
(Locked)
PIVOT the result set4m 20s
-
(Locked)
Challenge: Write a query with a subquery1m 2s
-
(Locked)
Solution: Write a query with a subquery8m 49s
-
(Locked)
Solution: Obtain information with a subquery5m 44s
-
(Locked)
-
-
-