Read our blogs, tips and tutorials
Try our exercises or test your skills
Watch our tutorial videos or shorts
Take a self-paced course
Read our recent newsletters
License our courseware
Book expert consultancy
Buy our publications
Get help in using our site
555 attributed reviews in the last 3 years
Refreshingly small course sizes
Outstandingly good courseware
Whizzy online classrooms
Wise Owl trainers only (no freelancers)
Almost no cancellations
We have genuine integrity
We invoice after training
Review 30+ years of Wise Owl
View our top 100 clients
Search our website
We also send out useful tips in a monthly email newsletter ...
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.
See our full range of SQL training resources, or test your knowledge of SQL with one of our SQL skills assessment tests.
This video has the following accompanying files:
File name | Type | Description |
---|---|---|
Create Movies Database with Genre Table.sql | SQL query | |
GenerateMoviesDatabase.sql | SQL query | |
GenerateUpdatedMoviesDatabase.sql | SQL query |
Click to download a zipped copy of the above files.
There are no exercises for this video.
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 above.
When you've finished viewing a video in full screen mode, just press the Esc key to return to normal view.
To improve the quality of a video, first click on the Settings icon:
Make sure yoiu're playing your video so that the icons shown above appear, then click on this gear icon.
Choose to change the video quality:
Click as above to change your video quality.
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 shown unless your connection speed is fast enough 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.
From: | Sanka |
When: | 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
From: | Andrew G |
When: | 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!
Kingsmoor House
Railway Street
GLOSSOP
SK13 2AA
Landmark Offices
99 Bishopsgate
LONDON
EC2M 3XD
Holiday Inn
25 Aytoun Street
MANCHESTER
M1 3AE
© Wise Owl Business Solutions Ltd 2024. All Rights Reserved.