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:

View full screen

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:

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:

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):

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.

This page has 1 thread Add post
07 Apr 21 at 10:17

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,

Sanka

12 Apr 21 at 07:39

Hi Sanka,

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!