From Excel to SQL - Joins (JOIN)
Joins allow us to combine information from various tables, which is a super important part of working with SQL! The dbfiddle website can be accessed for free and without an account at: - https://dbfiddle.uk/ Make sure to use the SQL Server dialect and the AdventureWorks sample database to be able to follow along with these examples! Looking to learn more about SQL joins? Check out my playlist below: - https://www.youtube.com/playlist?list=PLEiRgvTilK5rJilO6gc809Eg2Qajgeh02 --------------------------------------------------- For these examples, the rows are created on the fly. You're not expected to understand this yet, but it's provided so that you can run the SQL yourself if you want to: ``` WITH Employee AS ( SELECT * FROM ( VALUES (1, 'Alice', 1), (2, 'Bob', 1), (3, 'Charlie', 2), (4, 'Dave', 2), (5, 'Eve', 3) ) AS V(EmployeeID, EmployeeName, DepartmentID) ), Department AS ( SELECT * FROM ( VALUES (1, 'Sales'), (2, 'Marketing') ) AS V(DepartmentID, DepartmentName) ), Address AS ( SELECT * FROM ( VALUES (1, '1 Main Street', '2001-07-21', '2002-10-30'), (2, '2 Rocky Road', '2012-07-04', '2018-02-11'), (5, '5 Log Lane', '2009-11-19', '2020-03-15'), (5, '6 Claw Close', '2020-03-16', '2024-12-31') ) AS V(EmployeeID, Address, FromDate, ToDate) ) /* Edit this part */ SELECT Employee.EmployeeID, Employee.EmployeeName, Employee.DepartmentID, Department.DepartmentName, Address.Address, Address.FromDate, Address.ToDate FROM Employee INNER JOIN Department ON Employee.DepartmentID = Department.DepartmentID INNER JOIN Address ON Employee.EmployeeID = Address.EmployeeID ; ``` --------------------------------------------------- This is part of the From Excel to SQL playlist, available at: - https://www.youtube.com/playlist?list=PLEiRgvTilK5rhnVPQ_Tj3Q-CI0rGn_uiD Check out the previous video at: - https://youtu.be/65EFEtjYL9E ...and the next video at: - https://youtu.be/OQSLOGelJv0 The written version of this content is also available at: - https://billwallis.github.io/sql-learning-materials/from-excel-to-sql/main-concepts/join/ --------------------------------------------------- CHAPTERS 00:00 dbfiddle 00:28 Intro 02:35 Recap of Excel lookups 05:01 Lookups in SQL (LEFT JOIN) 09:53 Step-by-step walkthrough of JOIN 12:29 INNER JOIN in SQL 14:58 Lookups with multiple results (Excel) 18:00 Lookups with multiple results (SQL) 20:44 Step-by-step walkthrough of JOIN 22:58 INNER JOIN with multiple results 23:50 Multiple joins 27:26 Table aliases 29:19 Multiple join conditions 31:10 Step-by-step walkthrough of JOIN 32:53 Wrap up
Download
0 formatsNo download links available.