Correlated subquery in sql Part 60

preview_player
Показать описание
In this video we will discuss about Corelated Subqueries

In Part 59, we discussed about 2 examples that uses subqueries. Please watch Part 59, before proceeding with this video. We will be using the same tables and queries from Part 59.

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

In the example below, sub query is executed first and only once. The sub query resutls are then used by the outer query. In a non-corelated subquery, the subquery can be executed independently of the outer query.
Select [Id], [Name], [Description]
from tblProducts
where Id not in (Select Distinct ProductId from tblProductSales)

If the subquery depends on the outer query for its values, then that sub query is called as a correlated subquery. In the where clause of the subquery below, "ProductId" column get it's value from tblProducts table that is present in the outer query. So, here the subquery is dependent on the outer query for it's value, hence this subquery is a correlated subquery. Correlated subqueries get executed, once for every row that is selected by the outer query. corelated subquery, cannot be executed independently of the outer query.
Select [Name],
(Select SUM(QuantitySold) from tblProductSales where ProductId = tblProducts.Id) as TotalQuantity
from tblProducts
order by Name

Text version of the video

Slides

All SQL Server Text Articles

All SQL Server Slides

All Dot Net and SQL Server Tutorials in English

All Dot Net and SQL Server Tutorials in Arabic
Рекомендации по теме
Комментарии
Автор

U hv been serving the community for so many years. Thanks a lot

rezaulhoque
Автор

Thank you for all your videos! I understand that different heads have their own best way of understand things, but your explanations and samples is the one that suits mine!

aqasuncion
Автор

Hi Ravi, you are very welcome. Thank you for asking this question. We will discuss about the performance aspect between subqueries and joins in the next video. Please stay tuned.

Csharp-video-tutorialsBlogspot
Автор

Revisiting.

Thanks for educating the community

Thanks a lot

krismaly
Автор

Hi Varadharaj, sorry I don't have any videos on regular expressions yet. I will record and upload videos on regular expression and interview questions on sql server as soon as I can.

Csharp-video-tutorialsBlogspot
Автор

A precise and easy to understand tutorial. Liked it!

anuragvashishtha
Автор

Awesome video! Really cleared up the difference between correlated and non correlated subqueries. Thank you!

celina
Автор

fantastic. thank you for this excellent resource.

adamstearns
Автор

Great, easy to understand. Well done.

mysqlshorttutorials
Автор

Awesome!! Coaching institutes never teach us such things.

non-dualist
Автор

Very good explanation. Very good examples. Thank U Venkat!

krzysztofs
Автор

Hi Kudvenkat, Absolutely, I am addicted to your voice in explanation

shohailaamil
Автор

Venkat sir, you are really amazing to teach ms sql server. I learn lot from your video. It's really very helpful for fresher level and experienced level. Thank you very much sir❤❤❤

kasthuri
Автор

Thank u very much venkat,
and  please give me deep information about ' Subqueries'.

rammohan
Автор

Best out of all available in youtube,

dcgadagprasannakumar
Автор

Thank you! This was incomprehensible when I was reading it.

YuckNasty
Автор

hi venkat Thank you for sharing your knowledge

AVD
Автор

I enjoyed watching this video. Your explanation of basics is very interesting and makes clear understanding of topic. Thanks a lot and good luck!

krismaly
Автор

Venkat you are god :) Thanks for all the amazing videos :)

ishamadaan
Автор

Thank you very much for taking time to give feedback. In the description of this video, I have included the link for ASP .NET, C#, and SQL Server playlists. All the videos are arranged in logical sequence in these playlists, which could be useful to you. Please share the link with your friends who you think would also benefit from them. If you like these videos, please click on the THUMBS UP button below the video. For email alerts, when new videos are uploaded, you may subscribe to my channel.

Csharp-video-tutorialsBlogspot