Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 15

CS2072 Database Engineering Laboratory

&
CS2082 Database Management Systems
Laboratory
(LAB-8)

Prof. Sambit Bakshi


Computer Science and Engineering,
National Institute of Technology, Rourkela.
bakshisambit@nitrkl.ac.in
Full Outer Join
• This is a clause commonly used with select statement.

• Returns result containing rows from both left and right tables.

• When no matching rows exist for the row in the left table, the columns of
the right table will contain NULL. Likewise, when no matching rows exist
for the row in the right table, the column of the left table will contain
NULL.
Full Outer Join

SYNTAX EXAMPLE
SELECT SELECT_LIST FROM TABLE_T1 SELECT * FROM A
FULL OUTER JOIN
FULL OUTER JOIN B ON A.A =B.A;
TABLE_T2 ON JOIN_PREDICATE;
Full Outer Join
Full outer join can also be implemented using union of left outer join
and right outer join.

EXAMPLE
SELECT * FROM A LEFT OUTER JOIN
B ON A.A =B.A
UNION
SELECT * FROM A RIGHT OUTER JOIN
B ON A.A =B.A;
Self Join
• A self join allows you to join a table to itself.

• It helps query hierarchical data or compare rows within the same table.
Self Join

SYNTAX EXAMPLE
SELECT SELECT_LIST FROM TABLE_T1 SELECT * FROM A as A
INNER JOIN
INNER JOIN A as B ON A.A =B.A;
TABLE_T1 ON JOIN_PREDICATE;
Cross Join
• A cross join is a join operation that produces the Cartesian product of two
or more tables.

• Cartesian product is an operation which gives the result containing every


combination of both the tables.

• For example, with two sets A {x,y,z} and B {1,2,3}, the Cartesian product
of A x B is the set of all ordered pairs (x,1), (x,2), (x,3), (y,1) (y,2), (y,3),
(z,1), (z,2), (z,3).
Cross Join

SYNTAX EXAMPLE
SELECT SELECT_LIST FROM SELECT * FROM A
TABLE_T1 CROSS JOIN TABLE_T2; CROSS JOIN B;
Cross Join
Cross Join equivalent statement

EXAMPLE EXAMPLE
SELECT * FROM A , B; SELECT * FROM A
INNER JOIN
B ON 1=1;
Cross Join
• When we use some predicate in where clause in cross join it acts as inner
join.

EXAMPLE
SELECT * FROM A , B
WHERE A.A =B.A;
Update Join

• Join clauses along with the UPDATE statement to perform a cross-


table update.

• Inner Join /Left Outer Join is used in update join.


Update Join

SYNTAX EXAMPLE
UPDATE commissions
UPDATE TABLE_A SET t1.c1 =
SET commissions.commission =
t2.c2,
c.base_amount *
t1.c2 = expression, ... t.percentage
FROM TABLE_A FROM commissions c
[INNER | LEFT] JOIN INNER JOIN targets t
TABLE_B as t2 ON predicate ON c.target_id = t.target_id;;
WHERE predicate;
Delete Join

• Join clauses along with the Delete statement to perform a cross-table


delete.

• Inner Join /Left Outer Join is used in delete join.


Delete Join

SYNTAX EXAMPLE
DELETE TABLE_A FROM TABLE_A DELETE commissions from commissions c
[INNER | LEFT] JOIN INNER JOIN
TABLE_B ON predicate WHERE targets t ON c.target_id = t.target_id
predicate; where t.percentage<=0.5;
THANK YOU

You might also like