SQL Join Queries
SQL Join Queries
SQL JOIN
An SQL JOIN clause is used to combine rows from two or more tables, based on a
common field between them.
The most common type of join is: SQL INNER JOIN (simple join). An SQL INNER
JOIN return all rows from multiple tables where the join condition is met.
2 02 1996-09-19
2 03 1996-09-20
Notice that the "CustomerID" column in the "Orders" table refers to the customer in the
"Customers" table. The relationship between the two tables above is the "CustomerID"
column.
Then, if we run the following SQL statement (that contains an INNER JOIN):
Example
SELECT Orders.OrderID, Customers.CustomerName, Orders.OrderDate
FROM Orders
INNER JOIN Customers
ON Orders.CustomerID=Customers.CustomerID;
it will produce something like this:
INNER JOIN: Returns all rows when there is at least one match in BOTH tables
LEFT JOIN: Return all rows from the left table, and the matched rows from the
right table
RIGHT JOIN: Return all rows from the right table, and the matched rows from
the left table
FULL JOIN: Return all rows when there is a match in ONE of the tables
LEFT JOIN
or:
SELECT column_name(s)
FROM table1
RIGHT OUTER JOIN table2
ON table1.column_name=table2.column_name;