SQL Join 3 Tables: How-To with Example
Ғылым және технология
📝 Get my free SQL Cheat Sheets: www.databasestar.com/get-sql-...
🎓 Learn and become confident in SQL: databasestar.mykajabi.com/sql...
When working with SQL, you'll learn to join two tables together so you can get data from both of the tables.
But what about joining 3 tables?
This is possible to do in SQL. It works in a similar way to joining two tables and can be extended to join to 4 or 5 or many more tables.
In this video, you'll learn how to join 3 tables together in an SQL query, and follow a step-by-step example of a query that does this.
Пікірлер: 111
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
2 жыл бұрын
Thanks for the summary!
@szilardfineascovasa6144
Жыл бұрын
Good man, good man...
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
2 жыл бұрын
Glad it helped!
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
2 жыл бұрын
Thanks! I'm glad you found it useful and are able to understand it!
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
Жыл бұрын
Thanks! Glad it helped you understand it.
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
Жыл бұрын
Glad you found it helpful!
@jeanettemartinez8
Жыл бұрын
Me too!
Extremely easy to understand. Thank you so much for this!!!!
@DatabaseStar
2 жыл бұрын
Thanks, glad you liked it!
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
2 жыл бұрын
Glad it helped!
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
2 жыл бұрын
Glad it helped!
Clear and simple presentation, thank you very much
@DatabaseStar
2 ай бұрын
You are welcome!
Great video, still very relevant after 2 years!
@DatabaseStar
Жыл бұрын
Glad it was helpful!
Thank you, thank you, thank you!!! Very clear!
@DatabaseStar
3 жыл бұрын
Glad it was helpful!
Thanks for the illustrated example
@DatabaseStar
3 жыл бұрын
Glad you like it!
Thank you so much! Just 2 words, "Amazing Explanation"
@DatabaseStar
3 ай бұрын
Thanks a lot!
Thanks looks so easy now, well explained
@DatabaseStar
3 жыл бұрын
Thanks!
Thank you sir, could not have finished my MySQL project without. Thank you!!!!!!!!!
@DatabaseStar
2 жыл бұрын
Glad it helped!
Thanks, very easy to understand. :D
@DatabaseStar
3 жыл бұрын
Glad it helped!
Ive been rattling my brain for over an hour...to do what you did in 4:05....thank you
@DatabaseStar
3 жыл бұрын
I'm glad it has helped!
Fantastic! Thank you!
@DatabaseStar
9 ай бұрын
You’re welcome!
THANK YOU SO MUCH!
@DatabaseStar
3 жыл бұрын
Glad it helped!
Thank you!
@DatabaseStar
2 жыл бұрын
No problem!
Thanks so much! This saved me! Love from Sri Lanka
@DatabaseStar
Жыл бұрын
Glad it helped!
Thank you so much!
@DatabaseStar
5 ай бұрын
You're welcome!
Saved my life with this one
@DatabaseStar
2 жыл бұрын
Great to hear!
Thank you thank you! This helped me with a project for school. Thank you a ton!
@DatabaseStar
2 жыл бұрын
Awesome! Glad it helped.
@The.Wellerman
2 жыл бұрын
@@DatabaseStar I ended up passing the project. Again, thank you.
it would be great if you could include what the tables originally looked like and how they look after each statement.
@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.
It really helpful. Thanks
@DatabaseStar
3 жыл бұрын
Glad it was helpful!
i enjoyed the video.thank you dad
@DatabaseStar
Жыл бұрын
Thanks!
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
9 ай бұрын
Thanks! Yes you can use the same process for as many tables as you need.
Really specific and helpful,thank you
@DatabaseStar
3 жыл бұрын
Glad it was helpful!
Lifesaver thank you sooooo much
@DatabaseStar
2 жыл бұрын
Glad you found it helpful!
thanks a lot ❤️
@DatabaseStar
2 жыл бұрын
You’re welcome!
thanks to your video
@DatabaseStar
Жыл бұрын
Glad you found it useful!
Great explanation
@DatabaseStar
7 ай бұрын
Glad it was helpful!
Very helpful, thankyouuuu
@DatabaseStar
2 жыл бұрын
Glad it was helpful!
Thank u 👍
@DatabaseStar
4 ай бұрын
You’re welcome!
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
2 жыл бұрын
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.
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
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.
I learned something new
@DatabaseStar
2 жыл бұрын
That’s great to hear!
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
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.
Steps make it so easier Step 5
@DatabaseStar
Ай бұрын
That's true!
Mate I wish I had this back in uni.
@DatabaseStar
10 ай бұрын
Thanks! Yeah me too, I’m glad it’s helping many people.
How to add table with different column name
@DatabaseStar
2 жыл бұрын
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
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
2 ай бұрын
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
2 ай бұрын
@@DatabaseStar Thank you Sir for your answers, it makes sense! And thank u for your prompt reply!
Hello sir... Thanks for making this video. Result will get change if order of the tables changes? Pls reply. 🙏
@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
Жыл бұрын
@@DatabaseStar.. Thank you sir.
is language id the same number as publisher id in your example??
@DatabaseStar
Жыл бұрын
No, in this example they are different fields.
@deesee3622
Жыл бұрын
@@DatabaseStar so how are they equal to each other if they are not the same number type?
Please I did some but data do not display in the table
@DatabaseStar
Жыл бұрын
It could be because there is no matches based on your join criteria
@skeeterstudies8109
Жыл бұрын
@@DatabaseStar thank you very much, it is now working
hm, I am getting "ambiguous column name" error.
@DatabaseStar
2 жыл бұрын
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
2 жыл бұрын
That worked! Thanks for responding and clarifying!
How about show the result in a final form? Your title says with example. However no example....
@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_
5 ай бұрын
Like how can i get my tittle
This query wouldnt work lol
@DatabaseStar
9 ай бұрын
Oh, what error are you getting?
Lol show inner with left join . Don't show easy one
@DatabaseStar
2 жыл бұрын
Good point. Left join would be the same query with Left instead of Inner. But the results would be different
Thank you!
@DatabaseStar
2 жыл бұрын
You're welcome!