How to do Subqueries in SQL with Examples

  Рет қаралды 165,842

Becoming a Data Scientist

Becoming a Data Scientist

4 жыл бұрын

Step-by-step tutorial shows you how to use SQL subqueries in your SELECT statement & FROM and WHERE clauses!
Queries:
1) A subquery in the SELECT statement: SELECT customerid, freight, (SELECT AVG(freight) FROM orders) FROM orders
2) A subquery in the FROM clause: SELECT shipcountry, AVG(num_orders) FROM (SELECT customerid, shipcountry, count(*) AS num_orders FROM orders GROUP BY 1,2) sub GROUP BY 1
3) A subquery in the WHERE clause: SELECT * FROM orders WHERE employeeid IN (SELECT employeeid FROM employees WHERE LOWER(firstname) LIKE '%b%')
Get the Northwind Database: • How to Load a Sample P...
Support the Channel:
1) Subscribe: www.becomingads.com/o/youtube
2) DataCamp:
3) Udacity:

Пікірлер: 177
@honeyclover5038
@honeyclover5038 3 жыл бұрын
Finally, a break through. Finally, someone who explains the use of sub queries well.
@sarahemslie6105
@sarahemslie6105 4 жыл бұрын
This is really helpful; more so than my online course! I look forward to watching more of your videos. Thank you!
@Aaron-il5pk
@Aaron-il5pk 3 жыл бұрын
Thank you for telling us that even when you first learned this it was complex, because holy cow! I cannot wrap my head around this. I can kind of grasp whats going on, but I think you know the confusion that goes through a noob's mind. Thank you for your tutorials! I plan on watching many more of your videos.
@dabeast0623
@dabeast0623 3 жыл бұрын
CANNOT EXPLAIN ENOUGH HOW MUCH YOU SAVED MY LIFE.
@juliakristavilladiego4425
@juliakristavilladiego4425 3 жыл бұрын
Spending my Christmas binge watching your SQL tutorials haha so helpful. Thank you!!!!
@becomingADS
@becomingADS 3 жыл бұрын
Haha, sounds like a good Christmas to me!
@Peter-cx4ir
@Peter-cx4ir 2 жыл бұрын
Really great explanations. Easy to follow and perfect variety. Very much appreciate you posting these tutorials, they're beyond helpful. Thanks!
@jorgehernandezdominguez6574
@jorgehernandezdominguez6574 Жыл бұрын
WOW! the way you explained that is like first doing a table to then going and making a query from that table was a breakthrough for my understanding of the concept. I really admire people who can transform concepts into more digestible material. Thanks
@cameronp3157
@cameronp3157 3 жыл бұрын
Great video man! The best explanation of sub queries that I found! This is helping me a lot because I'm starting with a course of T-SQL
@kramoo
@kramoo 4 жыл бұрын
Absolutely amazing explanation and you give hope that you said it took you a while, now look at you.
@dfgndfghdfghdfgh
@dfgndfghdfghdfgh 3 жыл бұрын
super helpful and you explain stuff in a way where you don't rush through it but also don't take ages on it.
@kristiankelloway127
@kristiankelloway127 Ай бұрын
The idea that a subquery in a FROM statement creates a table and starting the query process from there was a real lightbulb moment - thank you
@EverythingData98
@EverythingData98 Жыл бұрын
I am getting ready for an internship using SQL as a data analyst and this made a ton of sense, thanks! I will be subscribing
@aadhyatiwari9688
@aadhyatiwari9688 6 ай бұрын
did you get the internship? just curious lol
@samuelopoku-acheampong5601
@samuelopoku-acheampong5601 3 жыл бұрын
Thanks for the tutorials, you have being of great help on this journey...Keep them coming
@topemorada
@topemorada 3 жыл бұрын
Your SQL knowledge is admirable.
@kw9303
@kw9303 Жыл бұрын
Just started a Business Systems Analyst entry level position that uses SQL everyday and this video has been so helpful! You explained it better than the corporate instructor, Khan Academy and my Udemy course! THANK YOU!!!!
@jcopas1826
@jcopas1826 2 жыл бұрын
This was very helpful. It saved me a lot of time. I understood it the first viewing and was able to apply the concepts with ease and complete my homework on time. Thank you, you do an excellent job. I will come back for future questions in SQL.
@jude3026
@jude3026 3 жыл бұрын
you just helped me through my project in SQL, thankss a lot!
@AlexMar-r
@AlexMar-r 7 ай бұрын
So easy to understand without broken English. Keep them coming!
@manaygun
@manaygun Жыл бұрын
Simple and direct. Just what I was needed.
@user-go2pt8ef4q
@user-go2pt8ef4q Жыл бұрын
Thank you for explaining it the way you did, it just clicked for me. Great stuff! Keep up the good videos.
@1mmoralls
@1mmoralls 2 жыл бұрын
Great video! Thank you so much for bringing a clear explanation of this topic. I look forward to viewing your other videos.
@andyn6053
@andyn6053 3 жыл бұрын
great videos! Its soo much easier too understand when watching your tutorials! Please do more advanced videos with window functions etc.
@ripndipp
@ripndipp 4 жыл бұрын
Excellent explanation, these sub queries got me messed up but this video helped. Your great and explaining and hoping you succeed with your channel, you seem like a genuine dude.
@becomingADS
@becomingADS 4 жыл бұрын
Thanks a lot for the kind words, means a lot!
@sopauljauck4163
@sopauljauck4163 3 жыл бұрын
Thank you for summing up subquery. Thank you.
@davidcoley4156
@davidcoley4156 2 жыл бұрын
A great, and much needed take on this subject.
@basetroll1627
@basetroll1627 3 жыл бұрын
Very helpful, some key explanation that made it "click" with me. And most of all, I like that you confess to your struggle at the beginning, beacause I have my though times right now....
@anievgenieva8267
@anievgenieva8267 3 жыл бұрын
Thank you! You look so positive and warm person :)
@EK-ee4gb
@EK-ee4gb 3 жыл бұрын
Awesome explanation. Thank you very much. I was completely lost on subqueries.
@woodynani4394
@woodynani4394 4 жыл бұрын
Thank you for your effort, keep moving
@petrblue
@petrblue Жыл бұрын
Thanks, great explanation!
@jaimetirado6130
@jaimetirado6130 2 жыл бұрын
Very helpful - thank you !!
@lazarus8011
@lazarus8011 2 жыл бұрын
Thanks helped me out heaps!
@SjeetjeMineetje
@SjeetjeMineetje 3 жыл бұрын
All your videos are very helpful and well explained! Helps me a lot in understanding SQL better. Are you planning on doing any more on SQL soon?
@jorgeduardo101
@jorgeduardo101 2 жыл бұрын
Awesome vid! thanks bud :)
@ALEX86ZILBER
@ALEX86ZILBER 10 ай бұрын
Thank you, a great explanation and examples for subqueries.
@mitul509
@mitul509 3 жыл бұрын
I like how you explain, keep up the good work.
@jeevak840
@jeevak840 6 ай бұрын
Actually for me this makes amazing sense. Thanks for the tutorial.
@tyroneogarrojr.453
@tyroneogarrojr.453 Жыл бұрын
Great video, very comprehensive!
@jhonpeteranduyon7247
@jhonpeteranduyon7247 3 жыл бұрын
Thank you! This helps me a lot.
@borjonx
@borjonx 3 жыл бұрын
This is exactly what I was looking for - thank you for sharing!
@borjonx
@borjonx 3 жыл бұрын
Does the internal table have to be the same as the outer table? "orders" in your example.
@srem1971
@srem1971 3 жыл бұрын
Great explanation. Thank you!
@josemunguia5660
@josemunguia5660 4 жыл бұрын
Great content! Thanks!
@shehanguruge7025
@shehanguruge7025 3 жыл бұрын
Well explained thanks a lot finally was able to get a better grasp of Sub Queries
@mattk3650
@mattk3650 4 жыл бұрын
thanks man, appreciate the explanation
@alexg97343
@alexg97343 Жыл бұрын
Great video easy to understand
@locke827
@locke827 5 ай бұрын
Great explanation. Thank you :)
@ced4298
@ced4298 2 жыл бұрын
Really good explanation. I will be glad to share this with developers who write "expensive" queries with complex join statements.😀
@PythonArms
@PythonArms 2 жыл бұрын
explained very well. thank you
@alejguz1552
@alejguz1552 Жыл бұрын
Thank you for sharing, I feel stupid not understanding, but you kind of make it clearer
@justineasterday4695
@justineasterday4695 4 жыл бұрын
Dude this was great.
@rackellewilkinson-alston
@rackellewilkinson-alston 3 жыл бұрын
loved this!!!
@williammandang
@williammandang 3 жыл бұрын
I didn't understand the concept one bit and I didn't understand why we should use them when I was in the university, but I understand now lol. Thanks for the tutorial. It's simple, yet really helpful for me
@kenchin5722
@kenchin5722 3 жыл бұрын
That was great Explaination.
@lamborghiniveneno8423
@lamborghiniveneno8423 2 жыл бұрын
And The search ends here.... Perfect 💯
@dkfwlqvkdlf35
@dkfwlqvkdlf35 3 жыл бұрын
AWESOME! thank you for your effort!
@liwaygorzon
@liwaygorzon 4 ай бұрын
hope you would keep on making SQL tutorials (or other programming language). you help me a lot in my review for my assessment. you have explained each topic very well! I'm learning a lot from you.
@jessibaby901
@jessibaby901 2 жыл бұрын
overwhelmed?! tuh... i am terrified! i came to you, from my online course, for some type of clarity. what did I get you might ask. HUMBLED! tfs this video anyway, I'm hopeful I will find some gems on your channel. -your new (maybe in over her head) subscriber
@kbishop9360
@kbishop9360 2 жыл бұрын
Thanks for this sql series
@nathanbenton2051
@nathanbenton2051 4 жыл бұрын
Great videos - keep it up!
@Beavin_it_up
@Beavin_it_up 2 жыл бұрын
thank god for this video!
@VaaniMogan
@VaaniMogan Ай бұрын
Thank you for this brilliant video. Please upload more :) :).
@orangefish9825
@orangefish9825 3 жыл бұрын
This helped, thank you!
@alvrey3390
@alvrey3390 3 жыл бұрын
Amazing Explanation Thank you 🙌
@omarkhaled6006
@omarkhaled6006 Жыл бұрын
amazing man good job
@paulntalo1425
@paulntalo1425 3 жыл бұрын
Thank you for the video
@williamredwine722
@williamredwine722 Жыл бұрын
Thank you for this video
@hungrygarfield
@hungrygarfield Жыл бұрын
You’re a real G
@maniijuan
@maniijuan Жыл бұрын
You sir are such a great teacher. Thank you
@nijulllee
@nijulllee Жыл бұрын
Thank you bro man 💥
@ahmedopeyemi2980
@ahmedopeyemi2980 10 ай бұрын
Where the heck have you been? You’re the only useful person on KZfaq!
@bhargav7476
@bhargav7476 3 жыл бұрын
I bought a course on Udemy, you solve like 10 doubts I had in just 1 video
@factorise001
@factorise001 2 жыл бұрын
keep it up!!
@TheOrionMusicNetwork
@TheOrionMusicNetwork 3 жыл бұрын
Brilliant explanation The online course I took had me lost at this part.
@jettecantoria
@jettecantoria Жыл бұрын
Thank you again
@Virtualexist
@Virtualexist 3 жыл бұрын
Hi there, I really liked the explanation, just a suggestion if you would give a very quick overview of the heads of the dataset so that it is easier to comprehend more how the query/subquery is extracting the data.
@marianneescande2685
@marianneescande2685 4 жыл бұрын
Very helpful! Thank you 😊
@becomingADS
@becomingADS 4 жыл бұрын
Glad it was helpful!
@GeloEd
@GeloEd 2 жыл бұрын
There are also subqueries in join. It's hard to find a material as good as this. Leaving a like and comment to support your channel.
@Robert8455
@Robert8455 2 жыл бұрын
Thanks!
@astonmargolis4391
@astonmargolis4391 Жыл бұрын
thank you!
@DataNovelties
@DataNovelties 3 жыл бұрын
Lovely. Thanls a lot for this great share 👌🙂
@dawitworku821
@dawitworku821 2 ай бұрын
Very helpful. Than you.
@gotchihaeyo1825
@gotchihaeyo1825 Жыл бұрын
Thank you.
@MrSoccerHighlighter
@MrSoccerHighlighter 4 жыл бұрын
Awesome!
@zoeteets9353
@zoeteets9353 2 жыл бұрын
This is so helpful! Thank you!! Rec: time stamps for each example
@alirezaghanbarzadeh1679
@alirezaghanbarzadeh1679 3 жыл бұрын
nice job!
@Joaquino991
@Joaquino991 3 жыл бұрын
Thank you!
@qpe04
@qpe04 2 жыл бұрын
Hi How's going ? Thank you for the video! I have a question about "inner query gets executed first", does it only apply to the subquery in FROM statement or no matter in SELECT/ FROM / Where statement ? Thank you very much!
@trucco16
@trucco16 3 жыл бұрын
you are a champion thanks a lot..(im buying your book also!!!)
@ankitachouhan6640
@ankitachouhan6640 3 жыл бұрын
Great explanation! Do you have a video for Correlated Subquery as well? It is super confusing
@felipestuardo123
@felipestuardo123 3 жыл бұрын
Hi! What program are you using to code? thank you! and what DBMS are u using
@jennifergonzalez6431
@jennifergonzalez6431 3 жыл бұрын
What does the 1,2 mean in the Group By 1,2?
@alialazawi2849
@alialazawi2849 Жыл бұрын
love u bro
@amoghnigam7276
@amoghnigam7276 2 жыл бұрын
THANK YOU
@Mika-hk3sm
@Mika-hk3sm 9 ай бұрын
does the "group by 1,2" also work in oracle db?
@Agadr
@Agadr 2 ай бұрын
thank youuu
@ninaa9294
@ninaa9294 3 жыл бұрын
Great Thank you. How can i use joins with it?
@noobedition9109
@noobedition9109 3 жыл бұрын
very helpful video. I just have a question, which one is better(most "performant") , doing a subquery or a join?
@cvendet1
@cvendet1 3 жыл бұрын
When doing a sub query (inner SELECT) and referencing it from the outer SELECT statement can I use a WHERE clause in the outer SELECT Statement or does it need to be in the Inner SELECT Statement? Similarly once I have established my inner SeELECT statement can I then use those columns in a CASE Statement?
@FilthyGreen
@FilthyGreen 2 жыл бұрын
This video saved my ass, THANK YOU.
@santosjaguar2000
@santosjaguar2000 3 жыл бұрын
Thank you
SQL WITH Statements (Common Table Expressions - CTE)
5:40
Becoming a Data Scientist
Рет қаралды 94 М.
Scary Teacher 3D Nick Troll Squid Game in Brush Teeth White or Black Challenge #shorts
00:47
Cat Corn?! 🙀 #cat #cute #catlover
00:54
Stocat
Рет қаралды 16 МЛН
New model rc bird unboxing and testing
00:10
Ruhul Shorts
Рет қаралды 24 МЛН
How to Filter with the WHERE clause in SQL
11:14
Becoming a Data Scientist
Рет қаралды 32 М.
When to Use a Subquery in SQL
8:50
Database Star
Рет қаралды 31 М.
Writing CASE WHEN Statements in SQL (IF/THEN)
5:50
Becoming a Data Scientist
Рет қаралды 85 М.
Stop using COUNT(id) to count rows
7:01
PlanetScale
Рет қаралды 372 М.
I've been using Redis wrong this whole time...
20:53
Dreams of Code
Рет қаралды 341 М.
6 SQL Joins you MUST know! (Animated + Practice)
9:47
Anton Putra
Рет қаралды 124 М.
Advanced Aggregate Functions in SQL (GROUP BY, HAVING vs. WHERE)
6:00
Becoming a Data Scientist
Рет қаралды 238 М.
We Learn SQL #9 | Simple subqueries in SQL
4:57
We Learn SQL
Рет қаралды 24 М.
Xiaomi SU-7 Max 2024 - Самый быстрый мобильник
32:11
Клубный сервис
Рет қаралды 356 М.
Looks very comfortable. #leddisplay #ledscreen #ledwall #eagerled
0:19
LED Screen Factory-EagerLED
Рет қаралды 1,7 МЛН
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,8 МЛН
S24 Ultra and IPhone 14 Pro Max telephoto shooting comparison #shorts
0:15
Photographer Army
Рет қаралды 9 МЛН
Как бесплатно замутить iphone 15 pro max
0:59
ЖЕЛЕЗНЫЙ КОРОЛЬ
Рет қаралды 3 МЛН
КРУТОЙ ТЕЛЕФОН
0:16
KINO KAIF
Рет қаралды 6 МЛН