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

  • @bhumikalamba186
    @bhumikalamba1862 жыл бұрын

    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...

  • @scottgee3089
    @scottgee30892 жыл бұрын

    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

    2 жыл бұрын

    Glad it helped!

  • @kalenwilson3319
    @kalenwilson33192 жыл бұрын

    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!

  • @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.

  • @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!

  • @vanpham4691
    @vanpham46912 жыл бұрын

    Extremely easy to understand. Thank you so much for this!!!!

  • @DatabaseStar

    @DatabaseStar

    2 жыл бұрын

    Thanks, glad you liked it!

  • @BensLab
    @BensLab2 жыл бұрын

    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!

  • @NOLONGERANONYMOUS
    @NOLONGERANONYMOUS2 жыл бұрын

    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!

  • @akutiaakuti3608
    @akutiaakuti36082 ай бұрын

    Clear and simple presentation, thank you very much

  • @DatabaseStar

    @DatabaseStar

    2 ай бұрын

    You are welcome!

  • @zabialy2919
    @zabialy2919 Жыл бұрын

    Great video, still very relevant after 2 years!

  • @DatabaseStar

    @DatabaseStar

    Жыл бұрын

    Glad it was helpful!

  • @lilbandit1979
    @lilbandit19793 жыл бұрын

    Thank you, thank you, thank you!!! Very clear!

  • @DatabaseStar

    @DatabaseStar

    3 жыл бұрын

    Glad it was helpful!

  • @patyue5012
    @patyue50123 жыл бұрын

    Thanks for the illustrated example

  • @DatabaseStar

    @DatabaseStar

    3 жыл бұрын

    Glad you like it!

  • @jordiadistira
    @jordiadistira3 ай бұрын

    Thank you so much! Just 2 words, "Amazing Explanation"

  • @DatabaseStar

    @DatabaseStar

    3 ай бұрын

    Thanks a lot!

  • @cfurnell6338
    @cfurnell63383 жыл бұрын

    Thanks looks so easy now, well explained

  • @DatabaseStar

    @DatabaseStar

    3 жыл бұрын

    Thanks!

  • @petecarroll7807
    @petecarroll78072 жыл бұрын

    Thank you sir, could not have finished my MySQL project without. Thank you!!!!!!!!!

  • @DatabaseStar

    @DatabaseStar

    2 жыл бұрын

    Glad it helped!

  • @devplus7131
    @devplus71313 жыл бұрын

    Thanks, very easy to understand. :D

  • @DatabaseStar

    @DatabaseStar

    3 жыл бұрын

    Glad it helped!

  • @damisohutchinson1832
    @damisohutchinson18323 жыл бұрын

    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!

  • @SZU1881
    @SZU18819 ай бұрын

    Fantastic! Thank you!

  • @DatabaseStar

    @DatabaseStar

    9 ай бұрын

    You’re welcome!

  • @camilomezu5008
    @camilomezu50083 жыл бұрын

    THANK YOU SO MUCH!

  • @DatabaseStar

    @DatabaseStar

    3 жыл бұрын

    Glad it helped!

  • @GreenSlugg
    @GreenSlugg2 жыл бұрын

    Thank you!

  • @DatabaseStar

    @DatabaseStar

    2 жыл бұрын

    No problem!

  • @hashanhemachandra4832
    @hashanhemachandra4832 Жыл бұрын

    Thanks so much! This saved me! Love from Sri Lanka

  • @DatabaseStar

    @DatabaseStar

    Жыл бұрын

    Glad it helped!

  • @samplaying4keeps
    @samplaying4keeps5 ай бұрын

    Thank you so much!

  • @DatabaseStar

    @DatabaseStar

    5 ай бұрын

    You're welcome!

  • @caryharris2358
    @caryharris23582 жыл бұрын

    Saved my life with this one

  • @DatabaseStar

    @DatabaseStar

    2 жыл бұрын

    Great to hear!

  • @The.Wellerman
    @The.Wellerman2 жыл бұрын

    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
    @redlobsta12 жыл бұрын

    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.

  • @alwaysbehappy1337
    @alwaysbehappy13373 жыл бұрын

    It really helpful. Thanks

  • @DatabaseStar

    @DatabaseStar

    3 жыл бұрын

    Glad it was helpful!

  • @elisamutiofficial2245
    @elisamutiofficial2245 Жыл бұрын

    i enjoyed the video.thank you dad

  • @DatabaseStar

    @DatabaseStar

    Жыл бұрын

    Thanks!

  • @jorhannyv3142
    @jorhannyv31429 ай бұрын

    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

    9 ай бұрын

    Thanks! Yes you can use the same process for as many tables as you need.

  • @liatarachel
    @liatarachel3 жыл бұрын

    Really specific and helpful,thank you

  • @DatabaseStar

    @DatabaseStar

    3 жыл бұрын

    Glad it was helpful!

  • @velinandreev173
    @velinandreev1732 жыл бұрын

    Lifesaver thank you sooooo much

  • @DatabaseStar

    @DatabaseStar

    2 жыл бұрын

    Glad you found it helpful!

  • @ashfaqmahmud
    @ashfaqmahmud2 жыл бұрын

    thanks a lot ❤️

  • @DatabaseStar

    @DatabaseStar

    2 жыл бұрын

    You’re welcome!

  • @Metanfetamino-san
    @Metanfetamino-san Жыл бұрын

    thanks to your video

  • @DatabaseStar

    @DatabaseStar

    Жыл бұрын

    Glad you found it useful!

  • @sgr7ss
    @sgr7ss7 ай бұрын

    Great explanation

  • @DatabaseStar

    @DatabaseStar

    7 ай бұрын

    Glad it was helpful!

  • @darcyyun6122
    @darcyyun61222 жыл бұрын

    Very helpful, thankyouuuu

  • @DatabaseStar

    @DatabaseStar

    2 жыл бұрын

    Glad it was helpful!

  • @AM-Boluke1210
    @AM-Boluke12104 ай бұрын

    Thank u 👍

  • @DatabaseStar

    @DatabaseStar

    4 ай бұрын

    You’re welcome!

  • @victorwestmann
    @victorwestmann2 жыл бұрын

    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

    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.

  • @xeskan
    @xeskan3 жыл бұрын

    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.

  • @jakebrown1879
    @jakebrown18792 жыл бұрын

    I learned something new

  • @DatabaseStar

    @DatabaseStar

    2 жыл бұрын

    That’s great to hear!

  • @hassanpatel3630
    @hassanpatel36302 жыл бұрын

    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.

  • @gauravsrivastava17
    @gauravsrivastava17Ай бұрын

    Steps make it so easier Step 5

  • @DatabaseStar

    @DatabaseStar

    Ай бұрын

    That's true!

  • @sunstryder
    @sunstryder10 ай бұрын

    Mate I wish I had this back in uni.

  • @DatabaseStar

    @DatabaseStar

    10 ай бұрын

    Thanks! Yeah me too, I’m glad it’s helping many people.

  • @saucegayuchiha8816
    @saucegayuchiha88162 жыл бұрын

    How to add table with different column name

  • @DatabaseStar

    @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

  • @fy8331
    @fy83312 ай бұрын

    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

    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

    @fy8331

    2 ай бұрын

    @@DatabaseStar Thank you Sir for your answers, it makes sense! And thank u for your prompt reply!

  • @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.

  • @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?

  • @skeeterstudies8109
    @skeeterstudies8109 Жыл бұрын

    Please I did some but data do not display in the table

  • @DatabaseStar

    @DatabaseStar

    Жыл бұрын

    It could be because there is no matches based on your join criteria

  • @skeeterstudies8109

    @skeeterstudies8109

    Жыл бұрын

    @@DatabaseStar thank you very much, it is now working

  • @wendya2309
    @wendya23092 жыл бұрын

    hm, I am getting "ambiguous column name" error.

  • @DatabaseStar

    @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

    @wendya2309

    2 жыл бұрын

    That worked! Thanks for responding and clarifying!

  • @sukumarpadhi8426
    @sukumarpadhi84262 жыл бұрын

    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_

    5 ай бұрын

    Like how can i get my tittle

  • @Moccalocca100
    @Moccalocca1009 ай бұрын

    This query wouldnt work lol

  • @DatabaseStar

    @DatabaseStar

    9 ай бұрын

    Oh, what error are you getting?

  • @X-Agn
    @X-Agn2 жыл бұрын

    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

  • @omarto7414
    @omarto74142 жыл бұрын

    Thank you!

  • @DatabaseStar

    @DatabaseStar

    2 жыл бұрын

    You're welcome!

Келесі