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
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.
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'
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!
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!)
@@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!
Wow! this looks like a great project! Especially being able to combine sql with a viz tool.
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
Nice one Sir
Thanks for this video
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.
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'
So useful, thanks👍
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!
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!)
@@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!
Awesome videos.
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