Page 56 - Modular_V2.0_SQL_Flipbook
P. 56

Table-STU

                                         Adm_no                Name               Game_id
                                            101                 Isha                1000
                                            102                Manish               1001
                                            103                Karan                1002

                   Select Name, Game_played from STU, GAMES;
              Output:
                                                  +--------+-------------+
                                                  | Name   | Game_played |
                                                  +--------+-------------+
                                                  | Karan  | Cricket     |
                                                  +--------+-------------+
                                                  | Manish | Cricket     |
                                                  +--------+-------------+
                                                  | Isha   | Cricket     |
                                                  +--------+-------------+
                                                  | Karan  | Rugby       |
                                                  +--------+-------------+
                                                  | Manish | Rugby       |
                                                  +--------+-------------+
                                                  | Isha   | Rugby       |
                                                  +--------+-------------+
                                                  | Karan  | Football    |
                                                  +--------+-------------+
                                                  | Manish | Football    |
                                                  +--------+-------------+
                                                  | Isha   | Football    |
                                                  +--------+-------------+

              These outputs shows that that you need some mechanism to produce useful results. As these cross
              products are making the data even more ambiguous so lets learn about equi join now.

              EQUI JOIN

              An  Equi  Join  is  a  type  of  SQL  join  that  retrieves  rows  from  two  or  more  tables  based  on  a
              condition that tests for equality between columns in the tables. It returns only those rows where

              the values in the specified columns are equal. This join is commonly used when the tables have
              a common column, such as an ID.

              Syntax:
                   SELECT table1.column1, table2.column2, ...
                                                                                     Output:
                   FROM table1, table2 '
                                                                                     +-------------+--------+
                   WHERE table1.common_column = table2.common_column; | Game_played | Name   |
                                                                                     +-------------+--------+
              Example using tables: STU and GAMES                                    | Cricket     | Isha   |
                                                                                     +-------------+--------+
                   Select Game_played, Name                                          | Rugby       | Manish |
                                                                                     +-------------+--------+
                   from GAMES, STU
                                                                                     | Football    | Karan  |
                   where GAMES.Game_id = STU.Game_id;                                +-------------+--------+

              Two tables GAMES and STU were joined in the above example of a common key called Game_id.
              This is called equi join.

                54
                      Touchpad MODULAR (Ver. 2.0)
   51   52   53   54   55   56   57   58   59   60   61