Here we discuss the concepts behind subqueries, and learn how and when we might use them.
Subqueries are one of the most advanced concepts to learn in SQL query writing. Seeing lots of examples and getting lots of practice will help solidify the concept.
As you begin using subqueries, be advised that a poorly structured subquery written against a large table or tables can impact overall query performance. Be careful if you are writing subqueries against data sets that consume tables with row counts in the million-plus row range.
This course does not cover the concept called Correlated Subqueries, which are slightly different in how they tie in with the outer query. Most of the time a regular subquery will do what you need, but correlated subqueries can be handy, too. These are especially heavy weight on the database engine, as they run the subquery many times; once per row in the outer query.
Hello, welcome to the final stage of our course on Querying Relational Databases. 0:01 In this stage we'll be learning about Subqueries. 0:10 A subquery is a query that is used in conjunction with another query. 0:14 Usually for the purposes of defining or 0:18 narrowing the results of the data returned by the main query. 0:21 There are a couple of different reasons you might need to use subquery. 0:26 You use a subquery when you don't necessarily know all the values you want 0:31 to include in a where clause or when you need to create a temporary view of 0:34 data that you can join to other data elsewhere in your database. 0:39 Here is an example of subquery syntax. Notice the second or lower query 0:44 is inside these parenthesis where our search criteria usually resides. 0:50 This is just one way subqueries can be used. 0:55 This is one of the tricky concepts to catch on to in SQL but 0:59 it's a very powerful tool for more advanced query writing. 1:03 The videos that follow will go into the different ways you can use sub-queries. 1:07
You need to sign up for Treehouse in order to download course files.Sign up