Page 155 - SQL
P. 155

GIVING




        Relational expressions can be chained together by naming the individual expressions using the
        giving keyword, or by embedding one expression within another.

        < relational algebra expression > giving < alias name >


        For example, consider the following expressions:
        select People where DepartmentID = 2 giving A
        project A over PersonName giving B


        This will result in table B below, with table A being the result of the first expression.












        The first expression is evaluated and the resulting table is given the alias A. This table is then
        used within the second expression to give the final table with an alias of B.


        Another way of writing this expression is to replace the table alias name in the second expression
        with the entire text of the first expression enclosed within brackets:
        project (select People where DepartmentID = 2) over PersonName giving B

        This is called a nested expression.



        NATURAL JOIN



        A natural join sticks two tables together using a common field shared between the tables.


        join < table 1 > and < table 2 > where < field 1 > = < field 2 >
        assuming that < field 1 > is in < table 1 > and < field 2 > is in < table 2 >.

        For example, the following join expression will join People and Departments based on the
        DepartmentID and ID columns in the respective tables:
        join People and Departments where DepartmentID = ID




















        https://riptutorial.com/                                                                             137
   150   151   152   153   154   155   156   157   158   159   160