SQL Joins
SQL Joins
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
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
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
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