1. JOINS AND SUBQUERIES IN
BIG DATAANALYSIS
N.SURATHAVANI MSc(IT)
Nadar Saraswathi College of Arts and Science,
Theni.
2. SQL JOIN:
A JOIN clause is used to combine rows from two or
more tables, based on a related column between them.
An SQL JOIN clause combines rows from two or
more tables. It creates a set of rows in a temporary
table.
3. Different Types of SQL JOINs:
JOIN (INNER)
LEFT (OUTER) JOIN
RIGHT (OUTER) JOIN
FULL (OUTER) JOIN
4. SQL INNER JOIN:
The INNER JOIN keyword selects records that have
matching values in both tables.
The INNER JOIN keyword selects all rows from
both tables as long as there is a match between the
columns.
5. INNER JOIN Syntax:
SELECT column_name(s)
FROM table1
INNER JOIN table2
ON table1.column_name = table2.column_name;
6. SQL LEFT JOIN:
The LEFT JOIN keyword returns all records from
the left table (table1), and the matched records from
the right table (table2).
The result is NULL from the right side, if there is no
match.
The LEFT JOIN keyword returns all records from
the left table (Customers), even if there are no
matches in the right table (Orders).
7. LEFT JOIN Syntax:
SELECT column_name(s)
FROM table1
LEFT JOIN table2
ON table1.column_name = table2.column_name;
8. SQL RIGHT JOIN:
The RIGHT JOIN keyword returns all records from
the right table (table2), and the matched records from
the left table (table1).
The result is NULL from the left side, when there is
no match.
The RIGHT JOIN keyword returns all records from
the right table (Employees), even if there are no
matches in the left table (Orders).
9. RIGHT JOIN Syntax:
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
10. SQL FULL OUTER JOIN:
The FULL OUTER JOIN keyword return all records
when there is a match in either left (table1) or right
(table2) table records.
FULL OUTER JOIN can potentially return very
large result-sets.
FULL OUTER JOIN and FULL JOIN are the same.
11. FULL OUTER JOIN Syntax:
SELECT column_name(s)
FROM table1
FULL OUTER JOIN table2
ON table1.column_name = table2.column_name
WHERE condition;
12. Subquery in SQL:
The subquery can be nested inside a SELECT,
INSERT, UPDATE, or DELETE statement or inside
another subquery.
A subquery is usually added within the WHERE
Clause of another SQL SELECT statement.
You can use the comparison operators, such as >, <,
or =. The comparison operator can also be a multiple-
row operator, such as IN, ANY, or ALL.
13. A subquery is also called an inner query or inner
select, while the statement containing a subquery is
also called an outer query or outer select.
A subquery must be enclosed in parentheses.
A subquery must be placed on the right side of the
comparison operator.
14. A subquery may occur in :
A SELECT clause
A FROM clause
A WHERE clause
15.
16. Subqueries:
A subquery must be enclosed in parentheses.
A subquery must be placed on the right side of
the comparison operator.
Subqueries cannot manipulate their results
internally, therefore ORDER BY clause cannot
be added into a subquery.
Use single-row operators with single-row
subqueries