Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 54 - Modular_V2.0_SQL_Flipbook
P. 54

    Output:
                                           +----------+-------+-------+-----------+
                                           | Stu_name | Age   | Fees  | Transport |
                                           +----------+-------+-------+-----------+
                                           | Rahim    | 18    | 12000 | 2000      |
                                           +----------+-------+-------+-----------+
                                           | Raja     | 19    | 13000 | 3000      |
                                           +----------+-------+-------+-----------+
                                           | Riya     | 18    | 12000 | 5000      |
                                           +----------+-------+-------+-----------+
                  Before diving into the specifics, let’s visualise how each type of join operates in combining data from
                  two tables:

                  Cartesian Product

                  The Cartesian product is also known as cross product. It is denoted by X. The degree of the new
                  relation will be the sum of the degrees of two relations in which cross product is executed.
                  Syntax:

                       SELECT * FROM table1, table2;

                      or
                       SELECT table1.col1, table2.col2 FROM table1, table2;

                  Let us consider the following tables:

                                      Table-STUDENTS                               Table-SUBJECTS

                                   Roll_no           Name                       Subject          Teacher
                               1                Rohit                       Maths            Mr. Rakesh
                               2                Amisha                      English          Ms. Pooja

                       Select * from STUDENTS, SUBJECTS;

                       or
                       SELECT STUDENTS.Roll_no,  STUDENTS.Name,  SUBJECTS.Subject,  SUBJECTS.Teacher
                       FROM STUDENTS, SUBJECTS;
                  STUDENTS X SUBJECTS will be:
                                          +---------+--------+---------+------------+
                                          | Roll_no | Name   | Subject | Teacher    |
                                          +---------+--------+---------+------------+
                                          | 2       | Amisha | Maths   | Mr. Rakesh |
                                          +---------+--------+---------+------------+
                                          | 1       | Rohit  | Maths   | Mr. Rakesh |
                                          +---------+--------+---------+------------+
                                          | 2       | Amisha | English | Ms. Pooja  |
                                          +---------+--------+---------+------------+
                                          | 1       | Rohit  | English | Ms. Pooja  |
                                          +---------+--------+---------+------------+

                  Columns after Cartesian Product: C1 + C2 = 2 + 2 = 4 columns ( Roll_No, Name, Subject, Teacher)

                  Rows after Cartesian Product: R1 × R2 = 2 × 2 = 4 rows (Every student is paired with every subject)

                    52
                          Touchpad MODULAR (Ver. 2.0)

| 49 50 51 52 53 54 55 56 57 58 59 |