Slides 2
Slides 2
( Learning outcomes )
Operations on Relations (Revised syllabus)
• Cartesian Product (revised syllabus)
• Union (revised syllabus)
• Intersection (revised syllabus)
• Minus (revised syllabus)
Types of Join (Revised syllabus)
• Inner Join
• Outer Join (LEFT Join, RIGHT Join, FULL Join)
• Cross Join / Cartesian Product (revised syllabus)
• Equi Join (revised syllabus)
• Natural Join (revised syllabus)
• Non-equi Join
• Additional search conditions in Joins
**NOTE:- MySQL queries are not case-sensitive
OPERATIONS ON RELATIONS: CARTESIAN PRODUCT
INDEX The Cartesian Product is a binary operation and is denoted by
Operation on relations a cross (x). The Cartesian Product of two relations A and B
• Cartesian can be denoted as A x B . The Cartesian Product of the two
relations produces a relation with all possible combinations
Product of the tuples of the two relations operated upon.
• Union The Cartesian Product yields a new relation which has:
• Intersection Degree of A x B = Degree of A + Degree of B
• Minus Cardinality of A x B =Cardinality of A * Cardinality of B
SUBJECT table with Degree=3, Cardinality=3 TEACHER table with Degree=4, Cardinality=5
NOTE:
Resultant table= SUBJECT x TEACHER with Degree=Total no. of
Degree=3+4=7, attributes/ fields/columns
Cardinality=3*5=15 Cardinality=Total no. of
Tuples/ Records/rows
CROSS Join / CARTESIAN PRODUCT/ UNRESTRICTED Join contd..
•Inner Join
table by combining column values of
two tables (table1 and table2) based
• Outer Join upon the join-predicate. The query
(LEFT Join, RIGHT Join,
compares each row of table1 with
FULL Join)
each row of table2 to find all pairs of
rows which satisfy the join-predicate
• Cross Join
(Join condition)
• Equi Join
• Natural Join
• Non-equi Join
Table 1 Table 2
• Additional search
conditions in Joins
INNER JOIN Example code
OUTER JOIN
• CONCEPT OF JOINS
In the OUTER JOIN all the
• TYPES OF JOIN
• Inner Join
content of the both tables are
integrated together either they
• Outer Join are matched or not.
(LEFT Join, RIGHT
TYPES OF OUTER JOINS
Join, FULL Join)
• Cross Join
LEFT OUTER JOIN / LEFT JOIN
• Equi Join RIGHT OUTER JOIN / RIGHT JOIN
• Natural Join FULL OUTER JOIN / FULL JOIN
• Non-equi Join
• Additional search ON keyword is used in the join
conditions in Joins predicate.
OUTER JOIN contd…
OUTER JOINS Description
LEFT OUTER JOIN returns all the rows from left table
or combined with the matching rows of
LEFT JOIN the right table. If you get no
matching in the right table it returns
Table L Table R
NULL values.
LEFT
LEFT OUTER JOIN / LEFT JOIN
LEFT
RIGHT OUTER JOIN / RIGHT JOIN
RIGHT
RIGHT OUTER JOIN / RIGHT JOIN
RIGHT
FULL OUTER JOIN / FULL JOIN
CROSS Join / CARTESIAN PRODUCT/
UNRESTRICTED Join contd..
• CONCEPT OF JOINS
• TYPES OF JOIN • Cross Join is used to return the Cartesian
• Inner Join product of two tables.
• Outer Join
• Unrestricted Join or Cartesian product of
both the tables gives all possible
(LEFT Join, RIGHT Join,
concatenations of all the rows of both the
FULL Join) tables.
SELECT *
FROM table1 NATURAL Join table2 SELECT *
WHERE
table1.column_name=table2.column_name;
FROM Teacher NATURAL JOIN Subject
WHERE
Teacher.sub_no=Subject.sub_no;
SELECT <column_list> SELECT *
FROM table1 Join table2 FROM Subject Join Teacher
USING (identical_column_name);
USING(sub_no);
NATURAL JOIN EXAMPLES…
• Non-equi Join
• Additional search
conditions in Joins
Non-Equi-Join condition
ADDITIONAL SEARCH CONDITIONS in JOINSc
JOIN condition on
Sub_no
ADDITIONAL SEARCH CONDITIONS in JOINS
Table Aliases, S, T
JOIN condition on Sub_no
Nested Order by
Stay safe. Stay aware. Stay healthy. Stay alert.