SQL Join 3 Tables: How-To with Example

  Рет қаралды 122,318

Database Star

Database Star

Күн бұрын

Пікірлер: 116
@MfknLemonBob
@MfknLemonBob 3 жыл бұрын
This video saved me. You explained this better than a text book, 15 minutes video, and a lecture from my prof combined did. Thank you
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Glad it helped!
@bhumikalamba186
@bhumikalamba186 2 жыл бұрын
Thanks for the lucid explanation. Summary: 1. SELECT columns to show from the first table 2. (INNER/OUTER) JOIN to the second table 3. add the columns to join ON 4. add any additional columns to step 1. 5. (INNER/OUTER) JOIN to third table 6.add the columns to join ON . The columns can belong to the first/second table and then join it with the column for the third table 7. add any additional columns to step 1.
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks for the summary!
@szilardfineascovasa6144
@szilardfineascovasa6144 Жыл бұрын
Good man, good man...
@bebe4235
@bebe4235 Жыл бұрын
hours upon hours of trying to figure this stuff out and your short video was all i needed. wish I could have found it sooner. THANKS!!
@DatabaseStar
@DatabaseStar Жыл бұрын
Glad you found it helpful!
@jeanettemartinez8
@jeanettemartinez8 Жыл бұрын
Me too!
@jeanettemartinez8
@jeanettemartinez8 Жыл бұрын
Thank you! I have watched so many videos where I get completely lost. I was able to follow along in the order and understand how! I really appreciate you and the method you teach.
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks! Glad it helped you understand it.
@BensLab
@BensLab 2 жыл бұрын
Thank You! I've been banging my head against a wall trying to figure this out. This video finally helped me. Many many thanks!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Glad it helped!
@kalenwilson3319
@kalenwilson3319 2 жыл бұрын
I have been trying to make sense of joins for the past 4 weeks - but the very essence of it had eluded me. NOW I understand! Thank you for simplifying this to the point where even I could understand it!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks! I'm glad you found it useful and are able to understand it!
@joadhra
@joadhra 9 ай бұрын
Thank you so much! Just 2 words, "Amazing Explanation"
@DatabaseStar
@DatabaseStar 9 ай бұрын
Thanks a lot!
@vanpham4691
@vanpham4691 2 жыл бұрын
Extremely easy to understand. Thank you so much for this!!!!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks, glad you liked it!
@damisohutchinson1832
@damisohutchinson1832 3 жыл бұрын
Ive been rattling my brain for over an hour...to do what you did in 4:05....thank you
@DatabaseStar
@DatabaseStar 3 жыл бұрын
I'm glad it has helped!
@petecarroll7807
@petecarroll7807 2 жыл бұрын
Thank you sir, could not have finished my MySQL project without. Thank you!!!!!!!!!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Glad it helped!
@hashanhemachandra4832
@hashanhemachandra4832 2 жыл бұрын
Thanks so much! This saved me! Love from Sri Lanka
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Glad it helped!
@NOLONGERANONYMOUS
@NOLONGERANONYMOUS 2 жыл бұрын
Needed to turn a setting off on certain records in one table based off of a category stored in another table. I'm just beginning to learn SQL for my job and this helped!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Glad it helped!
@caryharris2358
@caryharris2358 2 жыл бұрын
Saved my life with this one
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Great to hear!
@akutiaakuti3608
@akutiaakuti3608 8 ай бұрын
Clear and simple presentation, thank you very much
@DatabaseStar
@DatabaseStar 8 ай бұрын
You are welcome!
@Jorhanny33
@Jorhanny33 Жыл бұрын
You are a life saver, I am assuming this can be applied for even more than 3 tables, I definitely need to master MySQL for college projects, tysm.
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks! Yes you can use the same process for as many tables as you need.
@zabialy2919
@zabialy2919 2 жыл бұрын
Great video, still very relevant after 2 years!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Glad it was helpful!
@aiasaiascon3894
@aiasaiascon3894 Ай бұрын
In general - is it a more preferable method to add columns from the JOINs on a step by step pace ? And while following these steps, do you use a notepad (e.g) to write temporarily some parts of the SQL query ?
@DatabaseStar
@DatabaseStar 26 күн бұрын
Good questions! I think you should do whatever is easiest for you. I generally add the tables in the FROM clause first, then add the columns I want to see, because my SQL editor will usually show the available columns after I add the table to the query. I don't use a notepad to write parts of the query, but I often write my query in stages in the same SQL file.
@kirillzlobin7135
@kirillzlobin7135 5 күн бұрын
This channel is amazing
@DatabaseStar
@DatabaseStar 20 сағат бұрын
Thanks!
@The.Wellerman
@The.Wellerman 2 жыл бұрын
Thank you thank you! This helped me with a project for school. Thank you a ton!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Awesome! Glad it helped.
@The.Wellerman
@The.Wellerman 2 жыл бұрын
@@DatabaseStar I ended up passing the project. Again, thank you.
@redlobsta1
@redlobsta1 2 жыл бұрын
it would be great if you could include what the tables originally looked like and how they look after each statement.
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Thanks for the feedback! I’ll keep that in mind for future videos. I’ll see if I can add something for this to the Description area.
@elisamutiofficial2245
@elisamutiofficial2245 Жыл бұрын
i enjoyed the video.thank you dad
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks!
@sgr7ss
@sgr7ss Жыл бұрын
Great explanation
@DatabaseStar
@DatabaseStar Жыл бұрын
Glad it was helpful!
@cfurnell6338
@cfurnell6338 3 жыл бұрын
Thanks looks so easy now, well explained
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Thanks!
@hassanpatel3630
@hassanpatel3630 2 жыл бұрын
I’m using SQL management server and I need with the scenario, I have table A, junction table and Table B I need one row for table A and concatenate multiple rows of table b into one row with a comma. I’ve search the hours and can find no clues at all. I’d really appreciate it if you help me out
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Hey, I think you would need to use a technique called “string aggregation”. This is done using a function called string_agg in sql server. If you have the right results in separate rows showing for table a and b, you can then use this function to combine rows from table b into one row.
@fy8331
@fy8331 8 ай бұрын
Excuse me Sir I have a question. So in step 5 and 6, when joining the 3rd table and later specifying the target columns, suppose now I want to join based on the columns on the 2nd table & the 3rd table, not the 1st table & the 3rd table. What decides which join type to use? In this case does the sequence of specifying table names matter? What if there're more than 3 tables? Thank you in advance!
@DatabaseStar
@DatabaseStar 8 ай бұрын
Good questions! - When joining the 3rd table, you can join to any column in either the 1st table or 2nd table. It depends on how you write the query and add the columns and what makes sense for your data. - The results that you need will determine the join type to use. I see either an INNER JOIN or LEFT JOIN most commonly, depending on whether you want to see rows that have matches or not. - The sequence that you specify the tables will not matter for an INNER JOIN, but it will matter for a LEFT JOIN and RIGHT JOIN. - If there are more than 3 tables, you repeat the process: join to table 4, then specify the join condition to either table 1, 2, or 3.
@fy8331
@fy8331 8 ай бұрын
@@DatabaseStar Thank you Sir for your answers, it makes sense! And thank u for your prompt reply!
@SZU1881
@SZU1881 Жыл бұрын
Fantastic! Thank you!
@DatabaseStar
@DatabaseStar Жыл бұрын
You’re welcome!
@saucegayuchiha8816
@saucegayuchiha8816 3 жыл бұрын
How to add table with different column name
@DatabaseStar
@DatabaseStar 3 жыл бұрын
You should be able to use the same process. You can specify the column name in the ON clause of the join. For example, if table 2 has a column called some_other_id: JOIN table2 ON table1.id = table2.some_other_id
@skeeterstudies8109
@skeeterstudies8109 2 жыл бұрын
Please I did some but data do not display in the table
@DatabaseStar
@DatabaseStar 2 жыл бұрын
It could be because there is no matches based on your join criteria
@skeeterstudies8109
@skeeterstudies8109 2 жыл бұрын
@@DatabaseStar thank you very much, it is now working
@devplus7131
@devplus7131 3 жыл бұрын
Thanks, very easy to understand. :D
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Glad it helped!
@patyue5012
@patyue5012 4 жыл бұрын
Thanks for the illustrated example
@DatabaseStar
@DatabaseStar 4 жыл бұрын
Glad you like it!
@liatarachel
@liatarachel 3 жыл бұрын
Really specific and helpful,thank you
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Glad it was helpful!
@deesee3622
@deesee3622 Жыл бұрын
is language id the same number as publisher id in your example??
@DatabaseStar
@DatabaseStar Жыл бұрын
No, in this example they are different fields.
@deesee3622
@deesee3622 Жыл бұрын
@@DatabaseStar so how are they equal to each other if they are not the same number type?
@applikai
@applikai 3 жыл бұрын
The diagram at the beginning of the table is misleading. It shows it as A join B, B join C and A join C. The query however is just two joins, A join B, A join C. I was expecting the video to be dealing with a circular join. Thank you and keep them good videos on complex data modeling concepts coming.
@DatabaseStar
@DatabaseStar 3 жыл бұрын
That's a good point! I can update the thumbnail to make it clearer (I don't think I can update the video), but this is good to know.
@ashfaqmahmud
@ashfaqmahmud 2 жыл бұрын
thanks a lot ❤️
@DatabaseStar
@DatabaseStar 2 жыл бұрын
You’re welcome!
@lilbandit1979
@lilbandit1979 3 жыл бұрын
Thank you, thank you, thank you!!! Very clear!
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Glad it was helpful!
@darcyyun6122
@darcyyun6122 2 жыл бұрын
Very helpful, thankyouuuu
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Glad it was helpful!
@jakebrown1879
@jakebrown1879 2 жыл бұрын
I learned something new
@DatabaseStar
@DatabaseStar 2 жыл бұрын
That’s great to hear!
@velinandreev173
@velinandreev173 3 жыл бұрын
Lifesaver thank you sooooo much
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Glad you found it helpful!
@victorwestmann
@victorwestmann 3 жыл бұрын
Is this standard SQL, PL/SQL or T-SQL? Or it does not matter? :-) Thanks for the video! I just failed an interview with this EXACT question. Feeling awful. But life goes on!
@DatabaseStar
@DatabaseStar 3 жыл бұрын
This is standard SQL. The inner join, left join, and right join are all part of the SQL standard. There are some extra join features in specific database types, but I don't think I mentioned any of them in this video.
@sunstryder
@sunstryder Жыл бұрын
Mate I wish I had this back in uni.
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks! Yeah me too, I’m glad it’s helping many people.
@gauravsrivastava17
@gauravsrivastava17 7 ай бұрын
Steps make it so easier Step 5
@DatabaseStar
@DatabaseStar 7 ай бұрын
That's true!
@Sokratesin_Çaybardağı
@Sokratesin_Çaybardağı 2 жыл бұрын
thanks to your video
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Glad you found it useful!
@alwaysbehappy1337
@alwaysbehappy1337 4 жыл бұрын
It really helpful. Thanks
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Glad it was helpful!
@omarto7414
@omarto7414 2 жыл бұрын
Thank you!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
You're welcome!
@AM-HillsideWorks
@AM-HillsideWorks 10 ай бұрын
Thank u 👍
@DatabaseStar
@DatabaseStar 10 ай бұрын
You’re welcome!
@rapo107
@rapo107 Жыл бұрын
Hello sir... Thanks for making this video. Result will get change if order of the tables changes? Pls reply. 🙏
@DatabaseStar
@DatabaseStar Жыл бұрын
Thanks! No, the result should stay the same if you are using an Inner Join. If you're using an outer join (e.g. left join or right join) then yes the result will change.
@rapo107
@rapo107 Жыл бұрын
@@DatabaseStar.. Thank you sir.
@camilomezu5008
@camilomezu5008 3 жыл бұрын
THANK YOU SO MUCH!
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Glad it helped!
@wendya2309
@wendya2309 3 жыл бұрын
hm, I am getting "ambiguous column name" error.
@DatabaseStar
@DatabaseStar 3 жыл бұрын
Ah that’s because the column name exists in more than one table and the database does not know which column you want. If you add the table name and a . Before the column it should work. Eg customer.firstname instead of just firstname.
@wendya2309
@wendya2309 3 жыл бұрын
That worked! Thanks for responding and clarifying!
@sukumarpadhi8426
@sukumarpadhi8426 2 жыл бұрын
How about show the result in a final form? Your title says with example. However no example....
@DatabaseStar
@DatabaseStar 2 жыл бұрын
The final result is shown from about 3:16 where the query has fields from three different tables, which is the example. Were you looking for something else?\
@OBERE_
@OBERE_ 11 ай бұрын
Like how can i get my tittle
@Moccalocca100
@Moccalocca100 Жыл бұрын
This query wouldnt work lol
@DatabaseStar
@DatabaseStar Жыл бұрын
Oh, what error are you getting?
@X-Agn
@X-Agn 2 жыл бұрын
Lol show inner with left join . Don't show easy one
@DatabaseStar
@DatabaseStar 2 жыл бұрын
Good point. Left join would be the same query with Left instead of Inner. But the results would be different
@GreenSlugg
@GreenSlugg 2 жыл бұрын
Thank you!
@DatabaseStar
@DatabaseStar 2 жыл бұрын
No problem!
@samplaying4keeps
@samplaying4keeps 11 ай бұрын
Thank you so much!
@DatabaseStar
@DatabaseStar 11 ай бұрын
You're welcome!
Self Join in SQL
9:09
Database Star
Рет қаралды 49 М.
7 Database Design Mistakes to Avoid (With Solutions)
11:29
Database Star
Рет қаралды 94 М.
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
СИНИЙ ИНЕЙ УЖЕ ВЫШЕЛ!❄️
01:01
DO$HIK
Рет қаралды 3,3 МЛН
6 SQL Joins you MUST know! (Animated + Practice)
9:47
Anton Putra
Рет қаралды 229 М.
Using SQL to Select Records from Multiple Tables
10:32
MrBrownCS
Рет қаралды 78 М.
SQL Joins: A Guide and Examples
11:38
Database Star
Рет қаралды 29 М.
How to Correctly Define Many-To-Many Relationships in Database Design
7:07
SQL Joins: Difference Between Inner/Left/Right/Outer Joins
10:52
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.