Page 101 - PowerPoint Presentation
P. 101

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

               Week 3: SQL Syntax Continuation
               Objective: After the completion of the chapter, students will be able to:
                     Learn different Structured Query Language Syntax
                     Apply different SQL syntax in a database
                     Manipulate a database using different SQL Syntax

               SQL AND, OR and NOT Operators
               The WHERE clause can be combined with AND, OR and NOT Operators.
               The AND & OR operators are used to combine multiple conditions to narrow data in an SQL
               Statement. These two operators are called as the conjunctive operators.
                       -   The AND operator displays a record if all the table conditions separated by AND is
                          TRUE.
                       -   The  OR operator  display a  record  if  any of  the conditions  separated  by  OR  is
                          TRUE.
                       -   The NOT operator displays a record if the condition(s) is not TRUE.

               AND Syntax:
                   SELECT*FROM table_name WHERE condition1 AND condition2 AND condition3…;

               OR Syntax:
                     SELECT*FROM table_name WHERE condition1 OR condition2 OR condition3…;

               NOT Syntax:
                                  SELECT*FROM table_name WHERE NOT condition;

               Consider the ‘Persons’ table having the following records;
                                              ID     PersonName       Age      City
                                            1        Christian      22        Tanza
                                            2        John Mark      22        Trece
                                            3        Nigel          21        Indang
               AND Operator Example.
               The following SQL statement selects all the persons from the city of ‘Trece’, and whose age
               is more than 30 in the ‘Persons’ table.
                              SELECT*FROM Persons WHERE City = ‘Trece’ AND Age=22;

               OR Operator Example.
               The following SQL statement selects all the persons from the ‘Persons’ table where city is
               ‘Tanza’ OR ‘Trece’.
                               SELECT*FROM Persons WHERE City = ‘Tanza’ OR ‘Trece’;

               NOT Operator Example.
               The following SQL statement selects all the persons from ‘Persons’ table where city Is NOT
               ‘Tanza’
                                  SELECT*FROM Persons WHERE NOT City = ‘Tanza’;

               SQL BETWEEN Statement
               The BETWEEN…AND operators in SQL is used to select in-between values from the given
               range/values. The values can be numbers, text or dates.
               It is used in WHERE clause in SELECT, UPDATE and DELETE statement.
               WHERE BETWEEN is a shorthand for >= AND <=

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




                                                                                                 Page | 17
   96   97   98   99   100   101   102   103   104   105   106