Nested Queries | SQL | Tutorial 18

Поделиться
HTML-код
  • Опубликовано: 2 окт 2024
  • 🦒❤️ www.giraffeaca...

Комментарии • 154

  • @benweber3388
    @benweber3388 4 года назад +98

    Writing the queries separately and then combining them made the logic of nested queries much easier to understand. Nice vid!

    • @AD-do2rs
      @AD-do2rs 2 года назад +2

      Indeed .

    • @descobra5462
      @descobra5462 7 месяцев назад

      This guys way of teaching is amazing

  • @DannyMontealegre22
    @DannyMontealegre22 5 лет назад +39

    Couldn’t figure out my problem.. watched this video.. then solved my problem in less than 2 mins. Thx dude!

  • @marcusg5665
    @marcusg5665 4 года назад +26

    I feel Jim and Dwight sell more than Michael at any given time.
    Great video!

  • @isisdominguez4776
    @isisdominguez4776 2 года назад +13

    OMG, I was struggling with Nested subqueries, but now I certainly have a better insight about it. Thank you so much and the person who shared your video in a forum.

  • @e3uz
    @e3uz 4 года назад +1

    If in client there was not mng_id, is that a good query for the last exercise?
    SELECT client_id, client_name
    FROM client
    WHERE client_id IN (
    SELECT client_id
    FROM works_with
    WHERE emp_id IN(
    SELECT emp_id
    FROM employee
    WHERE super_id IN (
    SELECT mgr_id
    FROM branch
    WHERE mgr_id IN (
    SELECT emp_id
    FROM employee
    WHERE employee.first_name = 'Michael' AND employee.last_name = 'Scott'
    )
    ) OR (first_name = 'Michael' AND last_name = 'Scott')
    )
    )

  • @anthonyover
    @anthonyover 4 года назад +18

    YES!!!! Thank you. This was really clear. Taking my first database class via Zoom, needing all the help I can get lol!

  • @christopherrahme780
    @christopherrahme780 5 лет назад +2

    Assuming you don't know Michael Scott's ID:
    -- Clients handled by Michael Scott's branch
    SELECT client_name FROM client WHERE branch_id IN
    (SELECT branch_id FROM branch WHERE mgr_id IN
    (SELECT emp_id FROM employee WHERE first_name = "Michael" AND last_name = "Scott"));
    -- Or you can do
    SELECT client_name FROM client WHERE branch_id IN
    (SELECT branch_id FROM branch WHERE mgr_id IN
    (SELECT emp_id FROM employee WHERE CONCAT(first_name, " ", last_name) = "Michael Scott"));

  • @TheRealAK786
    @TheRealAK786 3 года назад +6

    Came for nested queries, stayed for the dataset. Love it thanks

  • @sabatinosalsano743
    @sabatinosalsano743 4 года назад +2

    in these cases would be more simple just using the join statement

  • @TheGoldenriff
    @TheGoldenriff 5 лет назад +9

    Can we also just use an inner join?
    Select * from employee inner join works_with where total_sales > 30,000 ?

    • @lawrencew8243
      @lawrencew8243 4 года назад +1

      I'm new to this stuff and wondering the same thing..

    • @TheBorjj
      @TheBorjj 4 года назад

      Any answers?

    • @jain4613
      @jain4613 4 года назад +2

      yes it gives the same result

    • @edinelezi7691
      @edinelezi7691 4 года назад

      Any nested correlated query can be rewritten as a normal query, it says in the book Fundamentals of Database Design.

  • @asrEthio
    @asrEthio 3 года назад +1

    Please make mor vedios on Database we need it!

  • @mching4473
    @mching4473 4 года назад +1

    Anyone having problems viewing this video in particular?

    • @mhmdbgskr
      @mhmdbgskr 4 года назад +1

      yes, I can only watch this video on 360p

  • @alisonlarson4882
    @alisonlarson4882 5 лет назад +6

    When is it more appropriate to use a nested query over a join? Or is it preference?

    • @djataberk1
      @djataberk1 5 лет назад

      Great question

    • @danjones9999
      @danjones9999 4 года назад

      Anyone?

    • @linda33528
      @linda33528 4 года назад

      literally my question and I can't find an answer either :)

    • @WarrenCromartie2
      @WarrenCromartie2 4 года назад +1

      Yes, a very good question. I would have used a table join for the first example in this tutorial, but as I'm relatively new to SQL, I assumed there was either a good reason not to, OR he was merely trying to demonstrate a principle.

  • @ericskelton5191
    @ericskelton5191 4 года назад +2

    Great video, but how dare you not even include Dwight in the employee table

  • @itsdaj
    @itsdaj 4 года назад +1

    Great video, just one problem though. You do not have Dwight in the employee table. :)

  • @beizhou1614
    @beizhou1614 2 года назад +2

    Thank you! Your explanation is so clear!

  • @subhamkumar9064
    @subhamkumar9064 3 года назад

    my approach:
    SELECT client.client_name
    FROM client
    WHERE client.branch_id=(
    SELECT employee.branch_id
    FROM employee
    WHERE first_name='Michael'
    );

  • @shreyansraghu6709
    @shreyansraghu6709 2 года назад +1

    Hi, I liked working on the data camp, are there any websites with a lot of tables and questions to solve more problems and practice?

  • @guitardude1007
    @guitardude1007 5 лет назад +2

    Lol love The Office examples. Great informative video

  • @mahinhossen4251
    @mahinhossen4251 Год назад

    for second query, we could also use
    SELECT client.client_id, client.client_name
    FROM client
    WHERE branch_id IN (
    SELECT employee.branch_id FROM employee
    WHERE employee.emp_id = 102
    );

  • @tejdeepak8092
    @tejdeepak8092 2 года назад +1

    hey mike, thanks for explaining the complex topic in SQL nested query!

  • @queryhsje7514
    @queryhsje7514 Год назад

    Hi, thanks for the video! Sorry I don't get it why in the first example you were using 'IN', while in the 2nd example you were using '='? Can you explain a little detail, please? Thanks.

  • @DevoutJourney
    @DevoutJourney Год назад

    Can you do this if your trying to pull from separate dbos? Or do I have to create a view with the info from each dbo I need?

  • @alcarajo61
    @alcarajo61 Месяц назад

    I liked the vid. You explain very well! However, isn't it a video for subqueries? I'm new to SQL but i'm under the impression you would have to go one step inner to get a nested query, right?

  • @TheMinaProject
    @TheMinaProject 2 года назад +2

    THANK YOU! BEST tutorial out there! Had no idea what was going on it class for the past 40 minutes and you sorted it in 10 😂

  • @lillycyriac6972
    @lillycyriac6972 5 лет назад +2

    Explanation are helpful but I do have one question.. isn't the first question to find out employees for a single client.. not sure the query address the question

    • @thesmallplateau
      @thesmallplateau 4 года назад

      I guess he means all employees who have sold +3k to one client (not a specific client). So if we have an employee who sold 1500 to a client and 1500 to another client should not be counted

  • @safiya1363
    @safiya1363 3 года назад +1

    Can I just say a HUGE thank you as I was stuck on this one coursework question

  • @Commander_HW
    @Commander_HW 3 года назад

    my profs couldn't even explain this as clear and you, and i paid her for the class.........

  • @arslanali1346
    @arslanali1346 3 года назад

    Please I have a few questions which I need help with.
    For these I have the tables ready but I am not sure if my queries are right. All the tables that I need are in section 1 which are done and completed. But for the queries from these tables are so confusing. I want to show you what I have done could you please show me if they are right . Please reply me if you can help me. I will send you all the queries I have done in the morning if you are ready to help me. Thank you
    God bless you.
    Kind regards
    Arslan

  • @SunshineFromWithin
    @SunshineFromWithin 2 года назад +1

    Fantastic videos, all of them. Thank you for doing this.

  • @alex-sd
    @alex-sd 2 года назад +1

    Awesome explanation for nested or subqueries. Thanks so much!

  • @elifece7847
    @elifece7847 5 лет назад +2

    can you give more questions for nested queries?

  • @popoporiBN
    @popoporiBN 2 года назад

    believe it or not our database design lecturer did not use practical example like this and just read of what syntaxes does from textbook. holy i just understood it in a minute!

  • @bradleynguyen1429
    @bradleynguyen1429 3 года назад

    May I asked why you would not use an IN with the client branch ID in the where clause, I don’t understand why parenthesis would used in this sense. Thank you

  • @god-speed03
    @god-speed03 2 месяца назад

    Life was good when we were giraffe academy's students

  • @hardedayormoses9996
    @hardedayormoses9996 6 месяцев назад

    Pls can I have the data u work on I have your whole video on SQL but I need your pdf

  • @Helloimtheshiieet
    @Helloimtheshiieet Год назад

    nobody uses where subqueries just write a nested left join lazy people maybe

  • @elij8852
    @elij8852 5 лет назад +4

    Great tutorials man. I have an internship coming up in just over a week. These videos are making me feel prepped for it.

  • @svens3722
    @svens3722 Год назад

    i need this with calculated columns. any suggestions?

  • @tucomax
    @tucomax 3 года назад

    Can't watch the video... There is an error when I try to play it.

  • @anuradhajha9798
    @anuradhajha9798 3 года назад

    thanks, wonderful session.

  • @caitlinwestby9663
    @caitlinwestby9663 4 года назад

    Couldnt you use a join to accomplish the same thing?
    SELECT employee.first_name, works_with.total_sales
    FROM employee
    JOIN works_with
    ON employee.emp_id = works_with.emp_id
    WHERE works_with.total_sales >= 30000;

    • @mrinalmishra1437
      @mrinalmishra1437 2 года назад

      He is teaching about nested queries. Later you'll get to know that we can use common table expressions as well instead of writing subqueries.

  • @mohammadmayar5544
    @mohammadmayar5544 2 года назад

    Can you make video of if condition and while loop as well please

  • @stevodoe4900
    @stevodoe4900 5 лет назад

    So, is it bad I didn't recognize the "re-brand" and my first thought was come on some guy stole "Mike's" video?? And, here I was going to subscribe. After a brief look at the videos, I realized my mistake and pounded that sub button. Because anyone with a hunger for computer knowledge this is a good place to start. The tutorials are simple and easy to follow for beginners and more advanced users.

  • @EzeChiappero
    @EzeChiappero 2 года назад

    Just 30 minutes ago, I upload a doubt. With the help of a mate, I got the answer right the way, great community!

  • @recklessvelociraptor2579
    @recklessvelociraptor2579 3 месяца назад

    6:11 why it is called foreign key?

  • @akj3388
    @akj3388 2 года назад

    In the very first subquery example, how would you display the client id as well along with employee's first and last name? I am happy if it repeats the name.

  • @dimitrisapostolakis8669
    @dimitrisapostolakis8669 4 года назад

    if you dont assume you know michael scott id cant you just do it through employee table?
    for exp
    select client.client_name from client
    where client.branch_id = (
    select employee.branch_id from employee
    where first_name='Michael' and last_name='Scott'
    //you could use LIKE instead of =
    limit 1);

  • @giving1106
    @giving1106 8 месяцев назад

    Very good breakdown, thank you!

  • @muneebbolo
    @muneebbolo 8 месяцев назад

    Love ♥ this tutorial
    Keep it up!

  • @gotchihaeyo1825
    @gotchihaeyo1825 2 года назад

    These can be done by using JOIN.

  • @protip2950
    @protip2950 4 года назад

    Why I can't play this video?

  • @juanfernandomoyanoramirez600
    @juanfernandomoyanoramirez600 2 года назад

    I come here from the google data analytics professional certificate and this video allowed me to understand this new concept. Thank you very much.

  • @ahmadhusayn539
    @ahmadhusayn539 2 года назад

    this is the code i came up with for the second question, can anyone tell me if it is correct
    select works_with.emp_id
    from works_with
    where works_with.emp_id in
    (
    select client.client_name
    from client
    where client.branch_id = 2
    );

  • @Pen_Da
    @Pen_Da 7 месяцев назад

    This made me understand the concept of nested queries better and quicker. The approach you conveyed within 5 mins is effective. Thank you so much

  • @missdhara6434
    @missdhara6434 3 года назад

    I have an exam tomorrow this whole nested queries thing can get pretty complicated if you dont under stand the basics of the dos and don'ts and when to use certain functions with nested queries.

  • @davidsmith6028
    @davidsmith6028 11 месяцев назад

    Awesome video, thanks so much

  • @mr.goldenball333
    @mr.goldenball333 2 года назад

    Thank you. It really helps!

  • @prajwalhiremath3248
    @prajwalhiremath3248 10 месяцев назад

    8:04
    can we write 'in' instead of "="?

  • @sviatoslavslivinskiy9330
    @sviatoslavslivinskiy9330 3 года назад +1

    Such a great tutorial.
    Thanks, man!

  • @hildakamiza3947
    @hildakamiza3947 5 лет назад +1

    you have helped alot .. clear and understandable explaination

  • @ujjawal6660
    @ujjawal6660 5 лет назад +1

    thnk u so much sir

  • @dawitworku821
    @dawitworku821 5 месяцев назад

    Very helpful. Than you.

  • @rshad4ever
    @rshad4ever 3 года назад

    omg, this is better than my professor

  • @EzeChiappero
    @EzeChiappero 2 года назад

    I don't understand fully the direfence between 'IN' statement and '=' command

  • @mmm-bj8zg
    @mmm-bj8zg Год назад

    Taught me something my teacher couldn't, appreciate it

  • @bradleynguyen1429
    @bradleynguyen1429 3 года назад

    Would it make a huge difference if the branch manager query was the outer query, and the client withing the nested query?

  • @laurenrackley4336
    @laurenrackley4336 3 года назад

    Can you do another video on a nested query but with group by? I am trying to use SQL to count adverse events for a clinical trial.

  • @WarrenCromartie2
    @WarrenCromartie2 4 года назад

    Very clearly explained. I'm just getting to grips with SQL, so forgive my ignorance! Would you use a nesting approach if you wanted to retrieve relational data for over 1000 items using Oracle where you can't input more than 1K items in a single search? Or is there a more efficient way of querying large numbers of inputs using Developer? Hope that makes sense :-)

  • @rootcause5322
    @rootcause5322 2 года назад

    This was lit 🔥 Thank u bruh...

  • @thecritico
    @thecritico Год назад

    Subscribed!!! Great videos with C and now SQL.

  • @NicolasSilvaVasault
    @NicolasSilvaVasault 5 лет назад

    i'm making an ecommerce website already made a db for it, but we are expanding so the nested model sounds like the best solution due to the filters and all that, but after watching this and making those huge queries (not difficult tho, just thinking about the whole mantainance and all the what would happen ifs), i feel like hierarchy model could be better, (can't work with mongodb since our hosting doesn't support it), what do you recommend me?

  • @KirillBezzubkine
    @KirillBezzubkine 4 года назад

    actually these queries are too easy. Make pls a more complicated query video

  • @parmarrutik7845
    @parmarrutik7845 2 года назад

    nice video i want this types of more scenerio base questions solutions

  • @lebzgold7475
    @lebzgold7475 2 года назад

    Thanks for simplifying the logic behind this!

  • @joelnada3483
    @joelnada3483 3 года назад

    Thank you very much bro....

  • @jbizzy4829
    @jbizzy4829 11 месяцев назад

    This was so helpful! Thanks

  • @thrang_eo
    @thrang_eo 6 лет назад +1

    Very Well Explained Sir ♥️♥️ Thank You

  • @nesreen1978
    @nesreen1978 5 лет назад +1

    I feel I should be contributing to your channel of how beneficial it is to me, thank you, Mike!

  • @GrumpySalmon
    @GrumpySalmon 3 года назад

    Can you create a video with nested queries and joins at the same time?

  • @shahzainahmed6851
    @shahzainahmed6851 2 года назад

    u are so good tbh , very clear

  • @DEEPAKS0306
    @DEEPAKS0306 3 года назад

    Being an office fanatic....i understood it better🤣👍👌

  • @chalmerilexus2072
    @chalmerilexus2072 3 года назад +1

    You are a Star...

  • @ndzalama1
    @ndzalama1 4 года назад

    Great examples, how can one play with that data (online practice

  • @eishaamir5601
    @eishaamir5601 2 года назад

    Love how you used people from the Office!!!

  • @Enkumnu
    @Enkumnu Год назад

    Thank you. Help a lot

  • @leeeric6292
    @leeeric6292 2 года назад

    To make it simple, why don't use "in" in all cases?

  • @SRISAILAPUBRAHMAJIBCE
    @SRISAILAPUBRAHMAJIBCE Год назад

    nice explanation 😇 sir

  • @danielhermawan4054
    @danielhermawan4054 2 года назад +1

    I'm still confused about the difference between the 'IN' and the '=' , any explanations? thanks in advance. Great video!

    • @EzeChiappero
      @EzeChiappero 2 года назад

      Me too, same doubt

    • @danielhermawan4054
      @danielhermawan4054 2 года назад +1

      @@EzeChiappero well now I got it , the different between the equal sign (=) and the 'IN' syntax is in it's implementation. Using 'IN' means we can look for value in a range of value, for example we can use : fruit IN ("apple","pineapple","orange"), it looks better than fruit = "apple" or fruit = "pineapple" or fruit = "orange".
      Hope that helps!

    • @EzeChiappero
      @EzeChiappero 2 года назад +1

      @@danielhermawan4054 Thanks!! I'm doing exercises right now and I'm sure that this advice will make sense for me later on. Thanks a lot for the reply!

    • @EzeChiappero
      @EzeChiappero 2 года назад

      @@danielhermawan4054 In the first exercise after reading your comment I get it. Thanks, Daniel!! Great community!!

    • @danielhermawan4054
      @danielhermawan4054 2 года назад

      Cool! You learned something today haha, I hope you'll do better and better!✨🔥

  • @ChicaSonidera
    @ChicaSonidera 2 года назад

    Great content, thanks.

  • @hanmwahx268
    @hanmwahx268 3 года назад

    Thank you so much dude

  • @julian.castro18
    @julian.castro18 3 года назад

    Thank you!

  • @seshurampilla4200
    @seshurampilla4200 5 лет назад

    I want to validate data from a table A and insert into another table B if value matches from A, how can we achieve it ?

  • @Merl-qi7ru
    @Merl-qi7ru Год назад

    why not just use join?

  • @rokunuzjahanrudro7571
    @rokunuzjahanrudro7571 Год назад

    Great explanation!!!

  • @yuneecorn
    @yuneecorn 4 года назад

    I wish I can give a million likes for this video. Thank you.

  • @sriramch5157
    @sriramch5157 Год назад

    We can use inner join

  • @balrajvirdee1087
    @balrajvirdee1087 Год назад

    Great video 👍🏽

  • @simplemente_humano
    @simplemente_humano 3 года назад

    Great video! Step by step, clear, organized! good job! Just subscribed!

  • @mashawickramasinghe195
    @mashawickramasinghe195 2 года назад

    Great video!!!👏