Basic HTML Version

|  | Table of Contents |  | View Full Version

Page 58 - Modular_V2.0_SQL_Flipbook
P. 58

    LEARNERS

                                              Learner_id       Learner_name          Subject

                                                  101              Aarav             Science

                                                  102              Meera           Commerce

                                                  104              Rahul               Arts

                       SELECT STAFF.Staff_name, LEARNERS.Learner_name, LEARNERS.Subject

                       FROM STAFF
                       INNER JOIN LEARNERS
                       ON STAFF.Staff_id = LEARNERS.Learner_id;

                  Output:
                                            +------------+--------------+----------+
                                            | Staff_name | Learner_name | Subject  |
                                            +------------+--------------+----------+
                                            | Rohit      | Aarav        | Science  |
                                            +------------+--------------+----------+
                                            | Amisha     | Meera        | Commerce |
                                            +------------+--------------+----------+

                  OUTER JOIN

                  An OUTER JOIN returns all the rows from one table and the matching rows from the other table. If
                  there is no matching row in the other table, the result will still include the row but with NULL (no

                  value) for columns from the table that doesn’t have a match.
                  There are two main types of Outer Joins:
                                                                                                         LEFT JOIN
                  1.  Left Outer Join (LEFT JOIN): It shows all rows from the left table and
                      the matching rows from the right table. If there is no match, it shows

                      NULL for the right table’s columns.                                           Table 1      Table 2
                      Syntax:

                       SELECT table1.column1, table2.column2

                       FROM table1
                       LEFT JOIN table2

                       ON table1.common_column = table2.common_column;
                      Example using tables: STAFF and LEARNERS

                       SELECT STAFF.Staff_name, LEARNERS.Learner_name, STAFF.Location
                       FROM STAFF

                       LEFT JOIN LEARNERS
                       ON STAFF.Staff_id = LEARNERS.Learner_id;

                    56
                          Touchpad MODULAR (Ver. 2.0)

| 53 54 55 56 57 58 59 60 61 62 63 |