SQL Joins Made VERY SIMPLE!

Поділитися
Вставка
  • Опубліковано 5 січ 2025

КОМЕНТАРІ • 12

  • @joeltorres1237
    @joeltorres1237 Рік тому +2

    Wow! this looks like a great project! Especially being able to combine sql with a viz tool.

  • @osoriomatucurane9511
    @osoriomatucurane9511 5 місяців тому

    Absolutely Awesome tutorial on join operations extended to filter.
    Thank you for highlighting the impact of cardinality on the size of the result set.
    I am left to understand the case use or when to decide to change the cardinality when performing the join, as displayed with the cte on the data wizardry web site under the sql basics healthcare

  • @nithinanthony1724
    @nithinanthony1724 Рік тому +2

    Nice one Sir

  • @igbegrowth4442
    @igbegrowth4442 4 місяці тому +1

    Thanks for this video

  • @joeltorres1237
    @joeltorres1237 Рік тому +1

    What was tripping me up was that patients table has only one Adelina Simonis for example and yet with left join on immunizations table I'm getting 10 instances of Adelina Simonis. Is this what you mean by a one to many? Bc there's many rows of that matching ID in immunizations table. It was a great lesson. And I like how you give a quick intro into what's next.

    • @DataWizardry
      @DataWizardry  Рік тому +1

      Great question! Yes, this is a one to many. And we'll be looking at this in the next video I will be publishing which is on cardinality.
      But yes, you are correct. The patient Adelina Simonis shows up once in the patient table. And 10 ten times in the immunizations table (had a stretch of 10 annual flu shots from 1974-1983).
      When the one to many join happens, some of the information starts to repeat itself however many number of times there was a match in the other table. In this case, ten rows are created to show each of those flu shots that she received. Though, the patient informaiton remains the same so it gets duplicated.
      This query should help visualize that a little bit better:
      SELECT pat.id,
      pat.first,
      pat.last,
      imm.description,
      imm.patient,
      imm.date as immunization_given
      FROM patients as pat
      INNER JOIN immunizations as imm
      on pat.id = imm.patient
      WHERE pat.id = 'e398337a-523b-fbed-1dc9-f308588869d1'

  • @konata_fan
    @konata_fan Рік тому +1

    So useful, thanks👍

  • @xavierwood6128
    @xavierwood6128 Рік тому +2

    First of all, this video and your previous 60 min. video were amazing! The explanations are concise and the examples are easy to follow! I had a question regarding your example of including the "pat.first = 'Adelina'" in the inner join statement. I tried using "where pat.first = 'Adelina' " after the join statement and I got the same result of 34 rows returned. Do you think one approach is better than the other, or would it just be a preference?
    Thank you for all of your work in making videos!

    • @DataWizardry
      @DataWizardry  Рік тому +2

      Great question!
      What's nice about SQL is that there's often multiple ways to achieve the same result. So, when I am faced with two different methods of achieving the same result, I go with the option that's easier to understand.
      So if I were tasked with looking up all patients named, Adelina, that had vaccines, my preferred way of writing it out would actually be:
      SELECT pat.id,
      pat.first,
      pat.last,
      imm.description,
      imm.patient
      FROM patients as pat
      INNER JOIN immunizations as imm
      on pat.id = imm.patient
      WHERE pat.first = 'Adelina'
      For me, it's just cleaner this way. Rather than the example in my tutorial where I used pat.first = 'Adelina' as a second condition in the join statement. Something about that approach just takes me a little longer to process what's happening. Whereas the above code is much more straight-forward.
      Making code as easy to understand as possible is a good habit to get into if you ever had to return to your work months later. (And your co-workers that might inherit the code, will appreciate you too!)

    • @xavierwood6128
      @xavierwood6128 Рік тому +2

      @@DataWizardry I appreciate the in-depth answer! I also find the "WHERE" method to be easier to digest, so we're on the same page there. Thanks once again and I'm looking forward to your next videos!

  • @drnamita9670
    @drnamita9670 Рік тому

    Awesome videos.

  • @karthikswamy8848
    @karthikswamy8848 Рік тому

    Hi , I am a pediatric Anesthesiologist .
    I have a lot of questions - can I have ur email id so that I can connnect with u.
    Thanks