14-MySQL Advance Cs 12
14-MySQL Advance Cs 12
3 Shirts
2 Pants
3x2 =6
i.e. 6
types are
possible
Cross Join – Mathematical Principle
Consider the two set A= {a,b} and B={1,2}
The Cartesian Product i.e. A x B = {(a,1) (a,2) (b,1) (b,2)}
Similarly, we may compute Cross Join of two tables by joining
each Record of first table with each record of second table.
RxS
R S
A B C C X Y
A B C C X Y
p q s s q r
p q s s q r
X p q s t n m
m n t t n m
p q s o p s
o p s o p s
m n t s q r
l m u
m n t t n m
The table will contain m n t o p s
(4x3=12) rows and 6 columns.
… … … … .. ..
So, degree will be added and
cardinality is multiplied for l m u o p s
Result table
Equi Join – Mathematical Principle
In Equvi Join, records are joined on the equality condition of
Joining Column. Generally, the Join column is a column which is
common in both tables (Foreign Key).
Consider the following table R and S having C as Join column.
R S T (Equi Join)
A B C C X Y
A B C C X Y
p q s s q r
p q s s q r
m n t t n m
m n t t n m
o p s o p s
o p s s p r
l m u
R S T (Natural Join)
A B C C X Y
A B C X Y
p q s s q r
p q s q r
m n t t n m
m n t n m
o p s o p s
o p s p r
l m u
All above
quarries give
same result
Example of Join Query
Ex. Find out the name of Employees working in same city from where
they belongs (hometown) .
Select Ename From EMP,DEPT Where Emp.City = Dept.Location;
OR
Select Ename From EMP JOIN DEPT ON Emp.City = Dept.Location;
Ex. Find out the all details of Employees with their department details.
Select * From EMP,DEPT Where Emp.DeptNo=Dept.DeptNo;
OR
Select * FROM EMP NATURAL JOIN DEPT;
Nested Query (A query within another query)
Sometimes it is required to join two sub-queries to solve a
problem related to the single or multiple table. Nested query is
the form of query which contains multiple query and inner query
evaluated first.
The general form to write Nested query is-
Select …. From <Table> Where <Column1> <Operator>
(Select Column1 From <Table> [Where <Condition>])