SELECTING DATA IN SQL VIDEOS▼
- SQL Queries Part 1 - Writing basic queries
- SQL Queries Part 2 - Sorting queries in SQL
- SQL Queries Part 3 - Using Criteria in Queries
- SQL Queries Part 4 - Creating Calculations in Queries
- SQL Queries Part 5 - Using CASE Statements
- SQL Queries Part 7 - Using Functions in Queries
- SQL Queries Part 8 - Calculations with Text
- SQL Queries Part 9 - Calculations with Dates
- SQL Queries Part 6 - Using Joins in Queries
- SQL Queries Part 10 - Grouping and Aggregating Data
- SQL Queries Part 11 - Subqueries
- SQL Queries Part 12 - Correlated Subqueries
Selecting data in SQL videos | SQL Queries Part 12 - Correlated Subqueries
Posted by Andrew Gould on 31 October 2012
A correlated subquery is a subquery which depends on an outer query for its values. If that doesn't make much sense, this video attempts to explain exactly what that means. You'll see how to build simple correlated subqueries, including why it's necessary to use table aliases, along with an explanation of what happens when you execute the query.
There are no files which go with this video.
Making a video bigger
You can increase the size of your video to make it fill the screen like this:
Play your video (the icons shown won't appear until you do), then click on the full screen icon which appears as shown at its bottom right-hand corner.
When you've finished viewing a video in full screen mode, just press the Esc key to return to normal view.
Improving the quality of a video
To improve the quality of a video, first click on the Settings icon:
Make sure you're playing your video so that the icons shown appear, then click on this gear icon at the bottom right-hand corner.
Choose to change the video quality:
Click on Quality as shown to bring up the submenu.
The higher the number you choose, the better will be your video quality (but the slower the connection speed):
Don't choose the HD option unless you have a fast enough connection speed to support it!
Is your Wise Owl speaking too slowly (or too quickly)? You can also use the Settings menu above to change your playback speed.
Hello Wise Owls,
I do have a question regarding the last case.
If the code in Line 14 is removed, will the output stays the same pls? Since the output is ORDERED BY y, we will always find the results rank by year, right?
Thanks in advance,
No, the results would be different if you remove line 14 from the last example. Line 14 is what makes this a correlated subquery. Without that line your results would return any film whose run time is longer than the average run time of every film in the table. With line 14 your results return each film whose run time is longer than the average run time of only those films made in the same year.
We aren't ranking results in this example, the ORDER BY clause was added simply to see the results more easily.
I hope that helps!