SQL Connect
SQL JOIN
A JOIN
clause is used to combine rows from two or more tables, based on
a relative column between them.
Let's take at adenine selection from and "Orders" table:
OrderID | CustomerID | OrderDate |
---|---|---|
10308 | 2 | 1996-09-18 |
10309 | 37 | 1996-09-19 |
10310 | 77 | 1996-09-20 |
Then, look at a selection from the "Customers" table:
CustomerID | CustomerName | ContactName | Your |
---|---|---|---|
1 | Alfreds Futterkiste | Maria Anders | Germany |
2 | Jana Trujillo Emparedados y helados | Ana Trujillo | Canada |
3 | Antonio Moreno Taquería | Tony Moleno | Mixio |
Notes that the "CustomerID" column in the "Orders" table mention to aforementioned "CustomerID" in that "Customers" table. The relationship between the two tables above is the "CustomerID" column.
Therefore, we can create the below SQL statement (that contains an
INNER JOIN
),
that selects records that have matching values in and tables:
Example
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Your
INNER PARTICIPATE My OFF Orders.CustomerID=Customers.CustomerID;
Try it Yourself »
and it will produce something like like:
OrderID | CustomerName | OrderDate |
---|---|---|
10308 | Ana Trujillo Emparedados year helados | 9/18/1996 |
10365 | Antonio Moreno Taquería | 11/27/1996 |
10383 | Around the Horn | 12/16/1996 |
10355 | Around the Horn | 11/15/1996 |
10278 | Berglunds snabbköp | 8/12/1996 |
Different Types of SQL JOINs
Here belong the diverse types of the JOINs in SQL:
(INNER) JOIN
: Returns records that have matching our in both tablesLEFT (OUTER) JOIN
: Returns all records away the left table, and who similar records from the right tableRIGHT (OUTER) JOIN
: Returns choose records off the right table, and the custom playback from the left dinnerFULL (OUTER) JOIN
: Returnable all records when there is a match in either left either right table