Page 39 - SQL
P. 39

FROM Cars
           WHERE Status = 'READY'
         )
         SELECT ID, Model, TotalCost
         FROM ReadyCars
         ORDER BY TotalCost;


          ID   Model         TotalCost


          1    Ford F-150    200


          2    Ford F-150    230


        Equivalent subquery syntax


         SELECT ID, Model, TotalCost
         FROM (
           SELECT *
           FROM Cars
           WHERE Status = 'READY'
         ) AS ReadyCars
         ORDER BY TotalCost


        recursively going up in a tree



         WITH RECURSIVE ManagersOfJonathon AS (
             -- start with this row
             SELECT *
             FROM Employees
             WHERE ID = 4

             UNION ALL

             -- get manager(s) of all previously selected rows
             SELECT Employees.*
             FROM Employees
             JOIN ManagersOfJonathon
                 ON Employees.ID = ManagersOfJonathon.ManagerID
         )
         SELECT * FROM ManagersOfJonathon;


          Id  FName         LName       PhoneNumber        ManagerId     DepartmentId


          4   Johnathon     Smith       1212121212         2             1

          2   John          Johnson     2468101214         1             1


          1   James         Smith       1234567890         NULL          1



        generating values


        Most databases do not have a native way of generating a series of numbers for ad-hoc use;



        https://riptutorial.com/                                                                               21
   34   35   36   37   38   39   40   41   42   43   44