You are on page 1of 7

Getting started with SQL JOINS

LEFT(OUTER) RIGHT (OUTER) FULL (OUTER)


INNER JOIN SELF JOIN UNION JOIN
JOIN JOIN JOIN

Returns all the Returns all the


rows from the left rows from the right Table is joined with
Returns all the Combines the
Returns only the table and the table and the itself. It is used to
rows from both results of two or
rows from both matching rows matching rows combine rows from
tables, including more SELECT
tables that have from the right from the left table. a single table
the matching and statements into a
matching values in table. If there is no If there is no based on a related
non-matching single result set.
both tables match, the result match, the result column between
rows.

s
will contain NULL will contain NULL them.

ow
values for all right values for all left
table's columns. table's columns.

Kn
hai
C ries
h se
Tec
Click here to learn more
INNER JOIN

SYNTAX
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;

QUERY
SELECT Customers.customer_id, orders.item
From Customers
INNER JOIN Orders
ON Orders.customer_id = Customers.customer_id

Click here to learn more content


LEFT JOIN

SYNTAX
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;

QUERY
SELECT Customers.customer_id, orders.item
From Customers
LEFT JOIN Orders
ON Orders.customer_id = Customers.customer_id

Click here to learn more content


RIGHT JOIN

SYNTAX
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;

QUERY
SELECT Customers.customer_id, orders.item
From Customers
RIGHT JOIN Orders
ON Orders.customer_id = Customers.customer_id

Click here to learn more content


FULL JOIN

SYNTAX
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;

QUERY
SELECT c.first_name, c.last_name, c.cust_id
FROM Customers c
FULL JOIN Orders o
ON c.cust_id=o.order_id
WHERE c.cust_id=o.order_id Click here to learn more content
SELF JOIN

TABLE A

SYNTAX
SELECT column_name(s)
FROM table1 T1, table1 T2
WHERE condition;

QUERY
SELECT a.name, b.salary
FROM Employee a, Employee b
WHERE a.managerId = b.id
AND a.salary > b.salary;
Click here to learn more content
UNION JOIN

SYNTAX
SELECT column_name(s) FROM table1
NOTE:
UNION
SELECT column_name(s) FROM table2; We build tuples by combining the
characteristics of two specified relations
QUERY using the FULL JOIN clause. When we
wish to merge the results of two searches,
SELECT Customers.first_name
we apply the UNION clause. They both
From Customers
UNION integrate data in unique ways.
SELECT Orders.order_id
From Orders
Click here to learn more content

You might also like