Page 78 - SQL
P. 78

2    John      Johnson  2468101214    1           1               400     23-03-2005    23-03-
         2005    01-01-2002
         3    Michael   Williams 1357911131    1           2               600     12-05-2009    12-05-
         2009    NULL
         4    Johnathon Smith    1212121212    2           1               500     24-07-2016    24-07-
         2016    01-01-2002


        Using a WHERE at the end of your SELECT statement allows you to limit the returned rows to a
        condition. In this case, where there is an exact match using the = sign:


         SELECT * FROM Employees WHERE DepartmentId = 1


        Will only return the rows where the DepartmentId is equal to 1:


         Id   FName     LName    PhoneNumber   ManagerId   DepartmentId    Salary  Hire_date
         CreatedDate   ModifiedDate
         1    James     Smith    1234567890    NULL        1               1000    01-01-2002    01-01-
         2002    01-01-2002
         2    John      Johnson  2468101214    1           1               400     23-03-2005    23-03-
         2005    01-01-2002
         4    Johnathon Smith    1212121212    2           1               500     24-07-2016    24-07-
         2016    01-01-2002



        AND and OR


        You can also combine several operators together to create more complex WHERE conditions. The
        following examples use the Employees table:


         Id   FName     LName    PhoneNumber   ManagerId   DepartmentId    Salary  Hire_date
         CreatedDate   ModifiedDate
         1    James     Smith    1234567890    NULL        1               1000    01-01-2002    01-01-
         2002    01-01-2002
         2    John      Johnson  2468101214    1           1               400     23-03-2005    23-03-
         2005    01-01-2002
         3    Michael   Williams 1357911131    1           2               600     12-05-2009    12-05-
         2009    NULL
         4    Johnathon Smith    1212121212    2           1               500     24-07-2016    24-07-
         2016    01-01-2002




        AND


         SELECT * FROM Employees WHERE DepartmentId = 1 AND ManagerId = 1


        Will return:


         Id   FName     LName    PhoneNumber   ManagerId   DepartmentId    Salary  Hire_date
         CreatedDate   ModifiedDate
         2    John      Johnson  2468101214    1           1               400     23-03-2005    23-03-
         2005    01-01-2002




        OR


        https://riptutorial.com/                                                                               60
   73   74   75   76   77   78   79   80   81   82   83