From the course: SQL Server Fundamentals: Master Basic Query Techniques

Unlock the full course today

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

Subqueries

Subqueries - SQL Tutorial

From the course: SQL Server Fundamentals: Master Basic Query Techniques

Start my 1-month free trial

Subqueries

- [Instructor] As we've discussed, one of the functions of inner joins is that they can be used to filter results sets, but there is another method that we can use to achieve this called a subquery. So we're going to use a subquery to get us the results we need to get all of the names for customers who live in Boston. So first let's start by running a query that will get us all of the customer names. And we know from our previous examples that that's going to be from the customer table. So we're going to select star from dbo.customer, and we're going to go ahead and give this a table alias. So let's run that and look at our data once again. We don't have the city name in this table so we can't filter on that condition right now. But if we can get access to information from the city_state_zip table, we can apply those filters. So what we're going to do is we're going to select star from dbo.city_state_zip. Let's see what that data set looks like, and figure out what city state zip IDs…

Contents