Essential Question: How can I connect two tables in SQL?
Mastery Objectives:
SWBAT create inner joins, left joins, right joins, and full joins between two tables.
Resources: https://www.youtube.com/watch?v=oLc9gVM8FBM
Inner Join:
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
Directions: There are several kinds of joins in SQL: Inner, left, right, self joins, and full joins. We are going to look at all of the different joins but for the final project, you only need to know about Inner joins. Inner joins are so common that you can use just the command JOIN instead of INNER JOIN. For this exercise, you will enter the queries below as they appear into the SQL Editor: https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_join, take a screenshot and describe the results. Then you will try the exercises below and see if you can figure out the correct syntax. Take a screenshot of the results and describe them. Paste all the screenshots into a google doc and then submit your google doc to google classroom.
SELECT Orders.OrderID, Customers.CustomerName FROM Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID;
SELECT Orders.OrderID, Customers.CustomerName FROM ((Orders
INNER JOIN Customers ON Orders.CustomerID = Customers.CustomerID)
INNER JOIN Shippers ON Orders.ShipperID = Shippers.ShipperID);
SELECT Customers.CustomerName, Orders.OrderID FROM Customers
LEFT JOIN Orders ON Customers.CustomerID = Orders.CustomerID
ORDER BY Customers.CustomerName;
SELECT Orders.OrderID, Employees.LastName, Employees.FirstName FROM Orders
JOIN Employees ON Orders.EmployeeID = Employees.EmployeeID
ORDER BY Orders.OrderID;
SELECT A.CustomerName AS CustomerName1, B.CustomerName AS CustomerName2, A.City
FROM Customers A, Customers B WHERE A.CustomerID <> B.CustomerID
AND A.City = B.City ORDER BY A.City;
https://www.w3schools.com/sql/exercise.asp?filename=exercise_join1
https://www.w3schools.com/sql/exercise.asp?filename=exercise_join2
https://www.w3schools.com/sql/exercise.asp?filename=exercise_join3