Page 178 - Artificial Intellegence_v2.0_Class_11
P. 178
Cartesian Product
The Cartesian product of two sets A and B, denoted by A × B, is the set of all ordered A
pairs where the first element is in A and the second element is in B. For example:
A = {1,2,3} and B = {2,3}
Then A x B = {(1,2), (1,3), (2,2), (2,3), (3,2), (3,3)}.
Brainy Fact
Set theory was created in 1874 by the German Mathematician Georg Cantor. Cantor defined infinite and well-
ordered sets and proved that there are more real numbers than natural numbers.
Introduction to Data Table Joins
You must have noted by now that relational databases are based almost entirely upon set theory. Let us now study
joins. A JOIN is used to combine rows from two or more tables, based on a related/common column between them.
Joining tables is essentially a Cartesian product followed by a selection criterion.
Different Types of Joins
There are 4 types of joins:
Inner Join
When INNER JOIN keyword is used, those records are selected that have matching values
in both the tables. In an inner join, only those tuples that satisfy the matching condition are Left Right
included, while the remaining tuples are excluded. Table Table
Syntax: SELECT table1.column1, table1.column2, table2.column1, .....
FROM table1
INNER JOIN table2
ON table1.matching_column = table2.matching_column;
where table1: First table, table2: Second table and matching_column: Column common to both the tables.
Left Outer Join
This join returns all records from the left table, and the matching records from the right
table. Left Right
Syntax: SELECT table1.column1, table1.column2, table2.column1, .... Table Table
FROM table1
LEFT JOIN table2
ON table1.matching_column = table2.matching_column;
Right Outer Join Left Right
It returns all records from the right table, and the matching records from the left table. Table Table
Syntax: SELECT table1.column1, table1.column2, table2.column1, ....
FROM table1
176 Touchpad Artificial Intelligence (Ver. 2.0)-XI

