2. Definition Of JOINS :-
An SQL join clause combines
records from two or more tables in a
database. It creates a set that can be
saved as a table or used as is. A JOIN
is a means for combining fields from
two tables by using values common
to each.
4. Natural Join - The NATURAL JOIN is a type of
equi-join and is structured in such a way
that, columns with same name of associate tables
will appear once only.
Eg - Select * FROM table1 NATURAL JOIN
table2;
EquiJoin - SQL EQUI JOIN performs a JOIN
against equality or matching column(s) values of the
associated tables. An equal sign (=) is used as
comparison operator in the where clause to refer
equality.
Eg - Select column_list FROM
table1, table2 WHERE table1.column_name
=table2.column_name
5. Self Join - SELF JOIN is used to join a table to
itself, as if the table were two tables, temporarily
renaming at least one table in the SQL statement.
Eg - SELECT a.column_name, b.column_name FROM
table1 a, table1 b WHERE a.common_filed =
b.common_field;
Outer Join –
Right Outer Join -
Left Outer Join
6. Right Outer Join - The LEFT JOIN keyword returns
all rows from the left table (table_name1), even if there
are no matches in the right table (table_name2).
Eg - SELECT column_name(s) FROM table_name1 LEFT JOIN
table_name2 ON table_name1.column_name=table_name2.column_name
Left Outer Join - The RIGHT JOIN keyword
returns all the rows from the right table
(table_name2), even if there are no matches in the
left table (table_name1).
Eg -SELECT column_name(s) FROM table_name1 RIGHT JOIN
table_name2 ON
table_name1.column_name=table_name2.column_name
7. A SQL nested query is a SELECT query that is
nested inside a SELECT, UPDATE, INSERT, or
DELETE SQL query. Here is a simple example
of SQL nested query:
Eg - SELECT Model FROM Product WHERE
ManufacturerID IN (SELECT ManufacturerID
FROM Manufacturer WHERE Manufacturer =
'Dell')
8. UNIONALL - Combines the results of two SELECT
statements into one result set.
SELECTCUST_NBR, NAME FROM CUSTOMER WHERE
REGION_ID = 5 UNION ALL SELECT
C.CUST_NBR, C.NAME FROM CUSTOMER C WHERE
C.CUST_NBR IN (SELECT O.CUST_NBR FROM
CUST_ORDER O, EMPLOYEE E WHERE
O.SALES_EMP_ID = E.EMP_ID AND E.LNAME =
'MARTIN');
9. • UNION - Combines the results of two SELECT
statements into one result set, and then
eliminates any duplicate rows from that result
set.
Eg - SELECT CUST_NBR, NAME FROM
CUSTOMER WHERE REGION_ID = 5 UNION
SELECT C.CUST_NBR, C.NAME FROM
CUSTOMER C WHERE C.CUST_NBR IN
(SELECT O.CUST_NBR FROM CUST_ORDER
O, EMPLOYEE E WHERE O.SALES_EMP_ID =
E.EMP_ID AND E.LNAME = 'MARTIN');
10. MINUS - Takes the result set of one SELECT
statement, and removes those rows that are also
returned by a second SELECT statement.
Eg - SELECT CUST_NBR, NAME FROM CUSTOMER
WHERE REGION_ID = 5 MINUS SELECT
C.CUST_NBR, C.NAME FROM CUSTOMER C WHERE
C.CUST_NBR IN (SELECT O.CUST_NBR FROM
CUST_ORDER O, EMPLOYEE E WHERE
O.SALES_EMP_ID = E.EMP_ID AND E.LNAME =
'MARTIN');
11. INTERSECT - Returns only those rows that are returned
by each of two SELECT statements.
Eg - SELECT CUST_NBR, NAME FROM CUSTOMER
WHERE REGION_ID = 5 INTERSECT SELECT
C.CUST_NBR, C.NAME FROM CUSTOMER C WHERE
C.CUST_NBR IN (SELECT O.CUST_NBR FROM
CUST_ORDER O, EMPLOYEE E WHERE
O.SALES_EMP_ID = E.EMP_ID AND E.LNAME =
'MARTIN');