Loading lesson path
clause is used to combine rows from two or more tables, based on a related column between them. Here are the different types of JOINs in SQL: (INNER) JOIN : Returns only rows that have matching values in both tables LEFT (OUTER) JOIN : Returns all rows from the left table, and only the matched rows from the right table RIGHT (OUTER) JOIN : Returns all rows from the right table, and only the matched rows from the left table FULL (OUTER) JOIN : Returns all rows when there is a match in either the left or right table Look at an order in "Orders" table:
10308
Formula
1996 - 09 - 18
Then, look at a customer in the "Customers" table:Here we see that the "CustomerID" column in the "Orders" table refers to the "CustomerID" in the "Customers" table. The relationship between the two tables above is the "CustomerID" column. Then, we can create the following SQL statement (that contains an
), that selects records that have matching values in both tables:
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDateINNER JOIN Customers ON Orders.CustomerID=Customers.CustomerID;and it will produce something like this:
10308
Formula
1996 - 09 - 1810365 Antonio Moreno TaquerÃa
Formula
1996 - 11 - 2710383
Formula
1996 - 11 - 1510355
Formula
1996 - 12 - 1610278 Berglunds snabbköp
Formula
1996 - 12 - 16