Page 102 - PowerPoint Presentation
P. 102

CAVITE STATE UNIVERSITY
                               T3 CAMPUS
                               Department of Information Technology          DCIT 55 – Advance Database System

               NOT BETWEEN Syntax:
                 SELECT*FROM table_name WHERE column_name NOT BETWEEN value1 AND value2;

               Example:       Consider the ‘Persons’ table having the following records.
                                              ID     PersonName       Age      City
                                            1        Christian      25        Tanza
                                            2        John Mark      23        Trece
                                            3        Nigel          21        Indang

               BETWEEN Operator Example
               The following SQL statement selects all the persons from the ‘Persons’ table whose age is
               between 23 and 25.
                              SELECT*FROM Persons WHERE Age BETWEEN 23 AND 25;
               The above query would produce the following result.
                                              ID     PersonName       Age      City
                                            1        Christian      25        Tanza
                                            2        John Mark      23        Trece
               Above SQL BETWEEN statement is equivalent to the following SELECT Statement
                               SELECT*FROM Persons WHERE Age >=23 AND Age<=25;

               NOT BETWEEN Operator Example
               The following SQL statement selects all the persons from the ‘Persons’ table whose age is not
               between 23 and 25.
                           SELECT*FROM Persons WHERE Age NOT BETWEEN 23 AND 25;
                                  SELECT*FROM Persons WHERE Age<35 OR Age>38

               SQL ORDER BY Clause
               The ORDER BY Clause in SQL is used with SELECT statement to sort the data in ascending
               or descending order, based on one or more columns.
               The ORDER BY keyword sorts the records in ascending order by default. To sort the records
               in descending order, use the DESC keyword.
               Syntax:
                 SELECT*FROM table_name ORDER BY column1_name, column2_name[ASC | DESC];
               Example:       Consider the ‘Persons’ table having the following records.
                                              ID     PersonName       Age      City
                                            1        Christian      25        Tanza
                                            2        John Mark      23        Trece
                                            3        Nigel          21        Indang
               ORDER BY Clause Example
                                     SELECT*FROM Persons ORDER BY City ASC;
               The above query would produce the following result:
                                              ID    PersonName       Age      City
                                            3       Nigel           21       Indang
                                            1       Christian       25       Tanza
                                            2       John Mark       23       Trece
               ORDER BY Clause with DESC Keyword Example
                                    SELECT*FROM Persons ORDER BY City DESC;
               The above query would produce the following result:
                                              ID     PersonName       Age      City
                                            2        John Mark      23        Trece
                                            1        Christian      25        Tanza
                                            3        Nigel          21        Indang



                                                                                                 Page | 18
   97   98   99   100   101   102   103   104   105   106   107