Page 278 - PYTHON-12
P. 278
Cartesian product for student X games:
student X games
mysql> SELECT Name, gname FROM student, games;
Rollno Name
Therefore, a Cartesian product is formed when no join conditions exist or Rohan Football
Jaya Football
are invalid. When we perform Cartesian product between two tables, all
Teena Football
the rows in the first table are joined to all the rows in the second table.
Rohan Lawn Tennis
Using Cartesian product operation results in a large number of rows as
Jaya Lawn Tennis
the output, so it is seldom used.
Teena Lawn Tennis
Equi Join
An Equi join is a simple SQL join condition that uses the equal to sign (=) as a comparison operator
for defining a relationship between two tables on the basis of a common field.
Syntax for Equi Join:
SELECT <column1>, <column2>,....
FROM <table1>, <table2>
WHERE <table1.column1> =
<table2.column2>;
For example,
Table: student Table: fees
Rollno Name Rollno Fee
1 Rohan 4 4500
2 Jaya 2 5500
3 Teena 3 5000
4 Diksha
Resultant Table
mysql> SELECT A.Rollno, Name, fee FROM Rollno Name Fee
4 Diksha 4500
student A, fees B
2 Jaya 5500
WHERE A.Rollno = B.Rollno;
3 Teena 5000
In the given SELECT statement, A and B are the alias names.
1. Inner Join: The Inner Join is a classification of equi join where
INNER JOIN
either of the equivalent queries gives the intersection of two
tables, i.e., it returns the rows which are common in both the
tables. table 1 table 2
Computer Science with Python–XII 12.48 OR mysql> SELECT A.Rollno, Name, fee
mysql> SELECT student.Rollno, Name, fee FROM student, fees
WHERE student.Rollno = fees.Rollno ORDER BY student.Rollno;
FROM student A, fees B WHERE A.Rollno =
B.Rollno ORDER BY A.Rollno;