Understanding Correlated Queries in SQL

  Рет қаралды 142,261

Edredo for Learners

Edredo for Learners

Күн бұрын

Пікірлер: 98
@vipu1212
@vipu1212 3 жыл бұрын
These 8 minutes solved hours' of my headache. Very well explained
@charan_75
@charan_75 3 жыл бұрын
For me, days of headache.
@N7__7
@N7__7 8 ай бұрын
😂
@TheDataMaestro
@TheDataMaestro 4 жыл бұрын
What makes this video awesome is: clear explanation of SQL feature, best practices of SQL, and alternative solutions. Those 3 are missing from many online courses.
@clovvnnor7113
@clovvnnor7113 10 ай бұрын
I was struggling with the logic of "WHERE dep = E. dep" part for almost a week, and ur small example is just so crispy and clear, I LOVE u man
@Sunny-wq9ue
@Sunny-wq9ue 3 ай бұрын
I still don't quite get that part? Could you explain please?
@adityabhatt4173
@adityabhatt4173 Жыл бұрын
Sharing the Code for the same- /* Understainding a correlated subquery and a common use case To find out employees who have salaries greater then the avg sal of their dept */ DROP TABLE IF EXISTS COLLEGE; CREATE TABLE COLLEGE ( ROLL_ID INT , NAME VARCHAR(20), SALARY INT, DEPT VARCHAR(20) ) INSERT INTO COLLEGE VALUES(1,'Aditya',2000,'CSE'); INSERT INTO COLLEGE VALUES(2,'Aman',3000,'EC'); INSERT INTO COLLEGE VALUES(3,'Arun',3000,'CSE'); INSERT INTO COLLEGE VALUES(4,'Amit',4000,'EC'); SELECT roll_id, NAME FROM COLLEGE O WHERE SALARY > (SELECT AVG(SALARY) FROM COLLEGE WHERE DEPT=O.DEPT GROUP BY DEPT);
@telephonerock
@telephonerock 11 ай бұрын
Best explanation for correlated queries on KZbin.
@oqant0424
@oqant0424 2 жыл бұрын
Great, thank you! Much easier to understand for those of us that need to visualize how it works. Spent the last 24 hours trying to understand this. Sincere thanks to you for this great explanation.
@akhdanarif9416
@akhdanarif9416 2 жыл бұрын
8 minutes of cure to people's headache all over the world. Best potion ever.
@pablo_brianese
@pablo_brianese 4 жыл бұрын
The most important part of the video is, in my opinion, the comparison with views and joins. It shows us why we would want to use correlated subqueries.
@kareemadesola6522
@kareemadesola6522 2 жыл бұрын
Could you tell me the graphics tool you used for this tutorial? Would really much appreciate it
@prinonmahdi1047
@prinonmahdi1047 2 жыл бұрын
Spent the last 24 hours trying to understand this. Sincere thanks to you for this great explanation.
@chaos8514
@chaos8514 2 жыл бұрын
how does it group does it group each time outer query runs?
@daniellestellrecht4105
@daniellestellrecht4105 7 жыл бұрын
Great, thank you! Much easier to understand than the Microsoft online course, for those of us that need to visualize how it works.
@dssingh9955
@dssingh9955 3 жыл бұрын
Hey, can you help me in some complex sub query??
@rajsekhardutta8891
@rajsekhardutta8891 3 жыл бұрын
Finally found a video that explains the topic in clear concise manner. Great explanation. Thanks!
@MySqueezingArm
@MySqueezingArm Жыл бұрын
Hey man, thank you for explaining something that I wasn't wrapping my head around. I thought it was a weird loop, but I realize it's just doing multiple comparisons (duh). Thank you so much.
@ranjithparuchuri6463
@ranjithparuchuri6463 2 жыл бұрын
shall we write a query as select * from emp where sal>( select avg(sal) from emp group by deptno) with out using corelated sub query ??
@diegomartins5846
@diegomartins5846 2 жыл бұрын
I would have solve it like that 👍
@Manoj_M_S
@Manoj_M_S 6 жыл бұрын
Better than so many websites and videos explaining corelated query.. Nandri
@rishi4
@rishi4 5 жыл бұрын
Thanks a ton I was having so much trouble wrapping my head around this, u really helped me out, but I have a question, it looks like this is modeled similar to a Join, when it comes to Joins If I understand correctly there are essentially 2 ways to do it, 1) using the where clause (which causes problems for full joins) 2) using a Join clause and an ON clause (which I think is the reccomended method) is there any way to use the On clause instead of a Where in a Co-related subqueiry or does it not matter in this case?
@muhammadsafiullah8428
@muhammadsafiullah8428 5 жыл бұрын
Emp as E doesn't mean that we are treating that specific RECORD/TUPLE as E. But it means that we are treating the table Emp as E.
@sindhujasekar4018
@sindhujasekar4018 5 жыл бұрын
E is known as alias name for the table that means the temporary name for the table
@Robay146
@Robay146 3 жыл бұрын
Wow, thank you so much! You have a gift for teaching! 🙏🏾
@elifgurel1262
@elifgurel1262 6 жыл бұрын
do you not have to group by the department first and take the avg?
@harshpandey8559
@harshpandey8559 5 жыл бұрын
No, since he's essential using a where clause. After the department filter, your avg(salary) essentially only grabs average for that specific department.
@TheDataMaestro
@TheDataMaestro 4 жыл бұрын
@@harshpandey8559 correct, and he explains that depending on size of table, this solution could use additional system resources. Using GROUP BY is an alternate solution.
@sknrendra
@sknrendra 3 жыл бұрын
your explanations are so easy to understand! greetings from Indonesia.
@radosawlament6794
@radosawlament6794 3 жыл бұрын
let me tell you my friend, all the comments are accurate, these 8 minutes saved me hours of analysis
@prithwishsen6293
@prithwishsen6293 5 жыл бұрын
Aggregate function cannot be used with where clause... So how come the inner query contains both togethee
@Cool94_4u
@Cool94_4u 5 жыл бұрын
bro where can be used with AGGREGATE func, the thing is you need to apply it on column which is not used on AGGREGATE func, ex. SELECT count(id) FROM test WHERE product_id10 HAVING count(id) >5
@habzy1987
@habzy1987 6 жыл бұрын
very very helpful explanation. your content and tone of voice and pace is excellent. :)
@kathielizabeth4790
@kathielizabeth4790 2 жыл бұрын
Good morning sir, where we will use this and only we will use in salaries...?
@lalit-singh-bisht
@lalit-singh-bisht Жыл бұрын
can you explain if we want to find the 3rd highest salary employee using nested query>???
@Shreymusic05
@Shreymusic05 4 жыл бұрын
How can we compare single value (Sal) with multiple values? Will it not cause error?
@urinamilovic2764
@urinamilovic2764 6 жыл бұрын
Your explanation is great!! Thank you so much!
@RonaldJon12
@RonaldJon12 6 жыл бұрын
Is the inner query executed just once or is it executed for every row returned by the outer?
@drew1035
@drew1035 6 жыл бұрын
Watch the video again. This is one of the first things he explains..
@tejuspn2406
@tejuspn2406 3 жыл бұрын
Very well explained! Loved it! Thank you!
@kobayashi8190
@kobayashi8190 Жыл бұрын
it is like iterate over rows in outer query (calling WHERE with column argument would iterate over rows) and copy the column value to the inner query (e.eid would evaluate to current row's eid value) sound like A nested loops in disguise...
@sagaromer8385
@sagaromer8385 Жыл бұрын
why don't we use group by for average salary?
@adilismail3593
@adilismail3593 4 жыл бұрын
What if i dont use E and directly use Emp. Dep
@danee593
@danee593 Жыл бұрын
What a great explanation!
@TheMaverickanupam
@TheMaverickanupam 4 жыл бұрын
Why can't we use group by dept in the subquery rather than referencing the outer query???????
@vikassharma2665
@vikassharma2665 5 жыл бұрын
The above example is taken from Stack Overflow but I like the way you explained :)
@sreepaljsp
@sreepaljsp 4 жыл бұрын
may be, stack over flow got the content from this video.. or even if it is from stack over flow, he explained it very well..
@suryadevararama2056
@suryadevararama2056 3 жыл бұрын
can the question that is solved in this video using corelated query be solved using JOIN?
@SarahFeng92
@SarahFeng92 Жыл бұрын
this was extremely helpful. thank you!
@OmPrakash-ot3nr
@OmPrakash-ot3nr 3 жыл бұрын
Can the explained question be done with the help with joins? If yes, can someone please share the query.
@muhammadahsanbutt2491
@muhammadahsanbutt2491 4 жыл бұрын
If u Come up with SQL Microsoft by solving it practically with Table Form It will be more efficient :)
@hoannguyen2219
@hoannguyen2219 3 жыл бұрын
so touching for an excellent video
@pengxiaohan3371
@pengxiaohan3371 4 жыл бұрын
Really good, sir! Clearly understood!
@kurakularajesh3460
@kurakularajesh3460 7 жыл бұрын
In Agregate function of avg() ,where class cant be used in aggregate function it will get error sir.
@mallikarjun5000
@mallikarjun5000 5 жыл бұрын
we can use
@kalashnikov203
@kalashnikov203 11 ай бұрын
Clear explanation ❤
@muhammadzakiahmad8069
@muhammadzakiahmad8069 2 жыл бұрын
Thankyou very well explained.
@subhasreegupta3937
@subhasreegupta3937 4 жыл бұрын
Really good explanation
@jullienb2055
@jullienb2055 4 жыл бұрын
Thanks bro, great video keep the good stuff
@jasminesultanah3270
@jasminesultanah3270 6 жыл бұрын
can you have subqueries within your inner query?
@peoples_channel
@peoples_channel 6 жыл бұрын
Jasmine Sultanah yes you can have...
@user-sj9xq6hb9p
@user-sj9xq6hb9p 3 жыл бұрын
Very well explained
@excessreactant9045
@excessreactant9045 3 жыл бұрын
This made me happy, thanks :)
@BHAWANISINGH-gi6jw
@BHAWANISINGH-gi6jw 4 жыл бұрын
Sir please upload video for class 11 ip mysql .it's a humble request
@abbloos
@abbloos 8 жыл бұрын
Thank you so much!! I didn't understand this part but now I do
@caniceokoro7741
@caniceokoro7741 8 жыл бұрын
Very helpful, thank you.
@pranjalgrover5447
@pranjalgrover5447 5 жыл бұрын
Well explained! Thank you!
@pantadeusz293
@pantadeusz293 3 жыл бұрын
Thank you very much!
@SelmaPreferParis
@SelmaPreferParis Ай бұрын
very helpful!
@phantrunghoaiminh
@phantrunghoaiminh 7 жыл бұрын
Great explanation! Thanks a lot! :)
@rajdeepdey7093
@rajdeepdey7093 6 жыл бұрын
very helpful....thank you very much
@plekkchand
@plekkchand 6 жыл бұрын
Very helpful. What language is being spoken?
@guilhermedealmeidacosta6644
@guilhermedealmeidacosta6644 6 жыл бұрын
Thank you for the video.
@SpaceNStuff
@SpaceNStuff 7 жыл бұрын
Helped me a lot, thnx
@navaneesubburaj3086
@navaneesubburaj3086 6 жыл бұрын
nice tutorial thank you so much
@veenasgoodtimes2781
@veenasgoodtimes2781 6 жыл бұрын
thank you so much......i was so helpless.......
@jenspeter437
@jenspeter437 7 жыл бұрын
thank you my friend
@deemaalabdulaali3147
@deemaalabdulaali3147 8 жыл бұрын
thank you so much
@Martin-zm8gq
@Martin-zm8gq 6 жыл бұрын
Curry inside a curry?
@bquimby5223
@bquimby5223 2 жыл бұрын
Bro. Thank you.
@Lumary
@Lumary 7 жыл бұрын
Thanks a lot! :)
@aleksandar5323
@aleksandar5323 6 жыл бұрын
Thank you!
@moutazka87
@moutazka87 3 жыл бұрын
Thank you
@suziewilliams2146
@suziewilliams2146 5 ай бұрын
Perfect!
@2002S40
@2002S40 4 жыл бұрын
IN subquery is one of worst practice to In SQL. Should've use join.
@korneelbaeten4040
@korneelbaeten4040 7 жыл бұрын
OK!
@aqibfayyaz1619
@aqibfayyaz1619 5 жыл бұрын
Nice
@techlovewithas445
@techlovewithas445 6 жыл бұрын
Thanks
@SquireVaporwave
@SquireVaporwave 7 жыл бұрын
thank you based SQL man
@yugiyuva
@yugiyuva 2 жыл бұрын
Too too too much thanks
@Xakanis
@Xakanis 6 жыл бұрын
I love you
@RamSharma-jy8mj
@RamSharma-jy8mj 9 ай бұрын
very good explanation
@atlasmazigh666
@atlasmazigh666 3 жыл бұрын
Thank you so much
@ishanfernando7521
@ishanfernando7521 2 жыл бұрын
Thank you
@PRANAVMAPPOLI
@PRANAVMAPPOLI 3 жыл бұрын
Nice
@ranellabjata5170
@ranellabjata5170 2 жыл бұрын
thanks
EXIST Function in SQL
8:04
Edredo for Learners
Рет қаралды 123 М.
Подсадим людей на ставки | ЖБ | 3 серия | Сериал 2024
20:00
ПАЦАНСКИЕ ИСТОРИИ
Рет қаралды 572 М.
小丑教训坏蛋 #小丑 #天使 #shorts
00:49
好人小丑
Рет қаралды 41 МЛН
SQL "difference between" interview questions (part 1)
8:20
Crack Concepts
Рет қаралды 633 М.
Correlated subquery in sql   Part 60
7:59
kudvenkat
Рет қаралды 244 М.
Nested Queries | SQL | Tutorial 18
10:23
Giraffe Academy
Рет қаралды 185 М.
We Learn SQL #13 | Intro to correlated subqueries in SQL
4:56
We Learn SQL
Рет қаралды 20 М.
6 SQL Joins you MUST know! (Animated + Practice)
9:47
Anton Putra
Рет қаралды 217 М.
When to Use a Subquery in SQL
8:50
Database Star
Рет қаралды 37 М.
SQL Subquery | Complete Guide with Correlated Subquery | #SQL Course #15
1:21:28
Подсадим людей на ставки | ЖБ | 3 серия | Сериал 2024
20:00
ПАЦАНСКИЕ ИСТОРИИ
Рет қаралды 572 М.