How to do Subqueries in SQL with Examples

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ม.ค. 2025

ความคิดเห็น • 178

  • @kristiankelloway127
    @kristiankelloway127 7 หลายเดือนก่อน +12

    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

  • @honeyclover5038
    @honeyclover5038 4 ปีที่แล้ว +87

    Finally, a break through. Finally, someone who explains the use of sub queries well.

  • @dabeast0623
    @dabeast0623 4 ปีที่แล้ว +19

    CANNOT EXPLAIN ENOUGH HOW MUCH YOU SAVED MY LIFE.

  • @juliakristavilladiego4425
    @juliakristavilladiego4425 4 ปีที่แล้ว +21

    Spending my Christmas binge watching your SQL tutorials haha so helpful. Thank you!!!!

    • @becomingADS
      @becomingADS  4 ปีที่แล้ว +3

      Haha, sounds like a good Christmas to me!

  • @Aaron-il5pk
    @Aaron-il5pk 4 ปีที่แล้ว +12

    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.

  • @EverythingData98
    @EverythingData98 2 ปีที่แล้ว +5

    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 ปีที่แล้ว +1

      did you get the internship? just curious lol

  • @jorgehernandezdominguez6574
    @jorgehernandezdominguez6574 ปีที่แล้ว +3

    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

  • @sarahemslie6105
    @sarahemslie6105 4 ปีที่แล้ว +39

    This is really helpful; more so than my online course! I look forward to watching more of your videos. Thank you!

  • @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!!!!

  • @AlexMar-r
    @AlexMar-r ปีที่แล้ว

    So easy to understand without broken English. Keep them coming!

  • @topemorada
    @topemorada 4 ปีที่แล้ว +2

    Your SQL knowledge is admirable.

  • @dfgndfghdfghdfgh
    @dfgndfghdfghdfgh 3 ปีที่แล้ว +1

    super helpful and you explain stuff in a way where you don't rush through it but also don't take ages on it.

  • @ripndipp
    @ripndipp 4 ปีที่แล้ว +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!

  • @bhargav7476
    @bhargav7476 3 ปีที่แล้ว +2

    I bought a course on Udemy, you solve like 10 doubts I had in just 1 video

  • @Michael-1qaz2wsx
    @Michael-1qaz2wsx ปีที่แล้ว

    Thank you for explaining it the way you did, it just clicked for me. Great stuff! Keep up the good videos.

  • @Peter-cx4ir
    @Peter-cx4ir 2 ปีที่แล้ว +2

    Really great explanations. Easy to follow and perfect variety. Very much appreciate you posting these tutorials, they're beyond helpful. Thanks!

  • @basetroll1627
    @basetroll1627 3 ปีที่แล้ว +1

    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....

  • @ahmedopeyemi2980
    @ahmedopeyemi2980 ปีที่แล้ว

    Where the heck have you been? You’re the only useful person on TH-cam!

  • @kramoo
    @kramoo 4 ปีที่แล้ว +7

    Absolutely amazing explanation and you give hope that you said it took you a while, now look at you.

  • @liwaygorzon
    @liwaygorzon 10 หลายเดือนก่อน

    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.

  • @cameronp3157
    @cameronp3157 3 ปีที่แล้ว +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

  • @davidcoley4156
    @davidcoley4156 3 ปีที่แล้ว

    A great, and much needed take on this subject.

  • @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

  • @ALEX86ZILBER
    @ALEX86ZILBER ปีที่แล้ว +1

    Thank you, a great explanation and examples for subqueries.

  • @jeevak840
    @jeevak840 ปีที่แล้ว

    Actually for me this makes amazing sense. Thanks for the tutorial.

  • @jcopas1826
    @jcopas1826 3 ปีที่แล้ว

    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.

  • @ced4298
    @ced4298 3 ปีที่แล้ว

    Really good explanation. I will be glad to share this with developers who write "expensive" queries with complex join statements.😀

  • @mitul509
    @mitul509 3 ปีที่แล้ว +1

    I like how you explain, keep up the good work.

  • @GeloEd
    @GeloEd 3 ปีที่แล้ว +1

    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.

  • @samuelopoku-acheampong5601
    @samuelopoku-acheampong5601 4 ปีที่แล้ว +2

    Thanks for the tutorials, you have being of great help on this journey...Keep them coming

  • @jude3026
    @jude3026 4 ปีที่แล้ว +1

    you just helped me through my project in SQL, thankss a lot!

  • @borjonx
    @borjonx 3 ปีที่แล้ว +1

    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.

  • @alejguz1552
    @alejguz1552 ปีที่แล้ว

    Thank you for sharing, I feel stupid not understanding, but you kind of make it clearer

  • @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.

  • @EK-ee4gb
    @EK-ee4gb 4 ปีที่แล้ว

    Awesome explanation. Thank you very much. I was completely lost on subqueries.

  • @anievgenieva8267
    @anievgenieva8267 3 ปีที่แล้ว +1

    Thank you! You look so positive and warm person :)

  • @maniijuan
    @maniijuan ปีที่แล้ว

    You sir are such a great teacher. Thank you

  • @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

  • @andyn6053
    @andyn6053 3 ปีที่แล้ว +1

    great videos! Its soo much easier too understand when watching your tutorials! Please do more advanced videos with window functions etc.

  • @TheOrionMusicNetwork
    @TheOrionMusicNetwork 4 ปีที่แล้ว +2

    Brilliant explanation The online course I took had me lost at this part.

  • @manaygun
    @manaygun 2 ปีที่แล้ว

    Simple and direct. Just what I was needed.

  • @timewithsopy
    @timewithsopy 4 ปีที่แล้ว +2

    Thank you for summing up subquery. Thank you.

  • @VaaniMogan
    @VaaniMogan 7 หลายเดือนก่อน

    Thank you for this brilliant video. Please upload more :) :).

  • @kayceeDis
    @kayceeDis 4 หลายเดือนก่อน

    This is an excellent video. Thank you!

  • @zoeteets9353
    @zoeteets9353 2 ปีที่แล้ว

    This is so helpful! Thank you!! Rec: time stamps for each example

  • @SjeetjeMineetje
    @SjeetjeMineetje 3 ปีที่แล้ว +6

    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?

  • @jennifergonzalez6431
    @jennifergonzalez6431 3 ปีที่แล้ว +2

    What does the 1,2 mean in the Group By 1,2?

  • @lamborghiniveneno8423
    @lamborghiniveneno8423 2 ปีที่แล้ว

    And The search ends here.... Perfect 💯

  • @tyroneogarrojr.453
    @tyroneogarrojr.453 2 ปีที่แล้ว

    Great video, very comprehensive!

  • @shehanguruge7025
    @shehanguruge7025 4 ปีที่แล้ว

    Well explained thanks a lot finally was able to get a better grasp of Sub Queries

  • @Virtualexist
    @Virtualexist 4 ปีที่แล้ว +1

    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.

  • @petrblue
    @petrblue 2 ปีที่แล้ว

    Thanks, great explanation!

  • @locke827
    @locke827 11 หลายเดือนก่อน

    Great explanation. Thank you :)

  • @alvrey3390
    @alvrey3390 3 ปีที่แล้ว

    Amazing Explanation Thank you 🙌

  • @alexg97343
    @alexg97343 2 ปีที่แล้ว

    Great video easy to understand

  • @debbietownsend1673
    @debbietownsend1673 ปีที่แล้ว

    I love the way you teach. You are clear and concise. How long have you been writing SQL?

  • @PythonArms
    @PythonArms 2 ปีที่แล้ว

    explained very well. thank you

  • @FrocketGaming
    @FrocketGaming 3 ปีที่แล้ว

    Question regarding the first example; could you not achieve the same result without a subquery by just adding avg(freight) as avg to the original select statement?

  • @lazarus8011
    @lazarus8011 3 ปีที่แล้ว

    Thanks helped me out heaps!

  • @kenchin5722
    @kenchin5722 3 ปีที่แล้ว

    That was great Explaination.

  • @DeenQuery
    @DeenQuery 4 ปีที่แล้ว

    Lovely. Thanls a lot for this great share 👌🙂

  • @kbishop9360
    @kbishop9360 2 ปีที่แล้ว

    Thanks for this sql series

  • @ka1r0ww
    @ka1r0ww 2 ปีที่แล้ว

    Quick question: what is the group by 1,2 doing? is that just ordering them by the order in which they columns were entered in the select statement?

  • @jaimetirado6130
    @jaimetirado6130 2 ปีที่แล้ว

    Very helpful - thank you !!

  • @AsmrAnimalStories
    @AsmrAnimalStories 3 ปีที่แล้ว

    I am here wondering if another way to write the first example with freight as
    SELECT AVG(Freight), customer_id
    FROM orders
    GROUP BY customer_id
    Would give same result as the Subquery in the first example?

  • @rackellewilkinson-alston
    @rackellewilkinson-alston 3 ปีที่แล้ว +1

    loved this!!!

  • @jorgeduardo101
    @jorgeduardo101 3 ปีที่แล้ว

    Awesome vid! thanks bud :)

  • @trucco16
    @trucco16 3 ปีที่แล้ว

    you are a champion thanks a lot..(im buying your book also!!!)

  • @matthewday4376
    @matthewday4376 2 ปีที่แล้ว

    thanks for the explanations. Why wouldn't you be able to take the average directly instead of needing to first subquery? Also, in the first subquery example, why do you need the subquery instead of writing SELECT AVG(freight)?

  • @akj3388
    @akj3388 3 ปีที่แล้ว +1

    It seems the subquery in the where clause is easiest to understand. SQ in the select statement is probably used to compare as it's gong to give only a single value irrespective of all the records. And finally SQ in the from can be used to create a temp table with aggregates; which will be used by outer query to do further aggregates.

  • @alirezaghanbarzadeh1679
    @alirezaghanbarzadeh1679 4 ปีที่แล้ว +1

    nice job!

  • @drillcream
    @drillcream 2 ปีที่แล้ว

    Beginner here with some experience. I don't get the group by 1 , 2. I'm used to grouping by the field name. Is Group BY 1, 2 the same as typing Group BY customerID, shipcountry ?

  • @gabrielhauschildt4674
    @gabrielhauschildt4674 ปีที่แล้ว +1

    Average number of orders per customer is a bit ambiguous as this could mean per specific customer instead of per one general customer.

  • @sandile13809
    @sandile13809 3 ปีที่แล้ว

    it should be a crime that universities get away with charging 50k of tuition for a shittier version of the stuff we learn for free. Really helpful!

  • @noneofurbusns3139
    @noneofurbusns3139 3 ปีที่แล้ว

    wait so why did you use select for avg the first time but the second time you used it without select. Is there a rule?

  • @NadegeP1
    @NadegeP1 3 ปีที่แล้ว

    Hi, may you help me with this if you don’t mind?
    how to exclude from the results similar values of the same row from two columns that are being compare. For example, in the same row, column 1 is 4567 and column 2 can be 4567 or 4568 or 4566. Since numbers are similar, the idea is to exclude that row if the number in column 2 is the same as column 1 or the number is plus or minus 1 of column 1’s number.
    If the column 1 is 4564 and column 2 is 4566, it would not be excluded since the number are not similar.
    I am trying to account for te value in each row of the column that has been rounded to the nearest whole number.

  • @woodynani4394
    @woodynani4394 4 ปีที่แล้ว +2

    Thank you for your effort, keep moving

  • @ankitachouhan6640
    @ankitachouhan6640 4 ปีที่แล้ว +1

    Great explanation! Do you have a video for Correlated Subquery as well? It is super confusing

  • @justineasterday4695
    @justineasterday4695 4 ปีที่แล้ว +1

    Dude this was great.

  • @FilthyGreen
    @FilthyGreen 3 ปีที่แล้ว

    This video saved my ass, THANK YOU.

  • @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?

  • @mattk3650
    @mattk3650 4 ปีที่แล้ว +1

    thanks man, appreciate the explanation

  • @aneeshchandramouli7440
    @aneeshchandramouli7440 4 ปีที่แล้ว +4

    Great explanation! What do the numbers 1 and 2 represent in the command "GROUP BY 1, 2" ?

    • @summer9380
      @summer9380 4 ปีที่แล้ว

      what i wondered too

    • @TheIgory1
      @TheIgory1 4 ปีที่แล้ว +1

      @@summer9380 My guess is referring to the columns in the select. As group be the first attribute then group by the second (cant remember the exact attribute names).

  • @hungrygarfield
    @hungrygarfield ปีที่แล้ว

    You’re a real G

  • @jhonpeteranduyon7247
    @jhonpeteranduyon7247 4 ปีที่แล้ว

    Thank you! This helps me a lot.

  • @nathanbenton2051
    @nathanbenton2051 4 ปีที่แล้ว +1

    Great videos - keep it up!

  • @nijulllee
    @nijulllee ปีที่แล้ว

    Thank you bro man 💥

  • @omarkhaled6006
    @omarkhaled6006 2 ปีที่แล้ว

    amazing man good job

  • @heatherline_
    @heatherline_ ปีที่แล้ว

    I don't get it why need to use subqueries for the select clause average freight. Why can't just use avg(frieght)? Arent that the same thing?

  • @josemunguia5660
    @josemunguia5660 4 ปีที่แล้ว +1

    Great content! Thanks!

  • @orangefish9825
    @orangefish9825 3 ปีที่แล้ว

    This helped, thank you!

  • @qpe04
    @qpe04 3 ปีที่แล้ว

    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!

  • @manisham9803
    @manisham9803 2 ปีที่แล้ว

    how can i get a total count of rows then find the average of it using a date range?

  • @noobedition9109
    @noobedition9109 4 ปีที่แล้ว

    very helpful video. I just have a question, which one is better(most "performant") , doing a subquery or a join?

  • @srem1971
    @srem1971 4 ปีที่แล้ว

    Great explanation. Thank you!

  • @Noah-357
    @Noah-357 4 ปีที่แล้ว

    What about inside joins( Select........ )?
    Also, where to find other good sources to understand subquery ?

  • @erinfitzpatric4058
    @erinfitzpatric4058 5 ปีที่แล้ว +1

    Great explanation...thanks!

    • @becomingADS
      @becomingADS  5 ปีที่แล้ว

      Thanks Erin! Glad it was helpful to ya!

    • @supermanmegaman2332
      @supermanmegaman2332 4 ปีที่แล้ว +1

      Why were you using Grouping By 1 and 2 in your subquieres?

  • @Beavin_it_up
    @Beavin_it_up 3 ปีที่แล้ว

    thank god for this video!

  • @inspirelegacy547
    @inspirelegacy547 3 ปีที่แล้ว

    Like how do WE make a Query of two cities in a STATION table with the shortest and longest CITY names, as well as their respective lengths (i.e.: number of characters in the name). If there is more than one smallest or largest city, choose the one that comes first when ordered alphabetically.

  • @felipestuardo123
    @felipestuardo123 4 ปีที่แล้ว

    Hi! What program are you using to code? thank you! and what DBMS are u using