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.
Correlated subqueries - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2019
Correlated subqueries
- [Instructor] Sub-queries can be used in place of join statements in a query as an alternate way of reviewing related information that's spread out across multiple tables. For instance, I can write two select queries that looks at the people and employees in the AdventureWorks database. Both of these tables are related based off of the BusinessEntityID column. In the first result, I see the information coming out of the Person.Person table, where I can get the first and last name of the person, and in the Employees table, I can relate the business entity ID to the job title of the person that's an employee. If I wanted to view all these details together, I might use an interjoin in the from clause of a query. That would look something like this. I'll select the Person.BusinessEntityID column, the Person.FirstName column, Person.LastName, and Employee.JobTitle. We'll pull these columns from the Person.Person table…