Page 483 - Computer_Science_F5
P. 483

Computer Science  (g) UNION
           The ‘UNION’ operator is used to combine the result sets of two or more SELECT
           statements. For example,
               SELECT name FROM employees
          FOR ONLINE READING ONLY
               UNION
               SELECT name FROM contractors;


           (h) EXISTS
           The ‘EXISTS’ operator checks whether any records exist in a subquery. For example,
               SELECT name
               FROM employees

               WHERE  EXISTS (SELECT 1  FROM departments  WHERE  departments.
               department_id = employees.department_id);

           (i) IN
           The ‘IN’ operator allows you to specify multiple values in a WHERE clause. For
           example,
               SELECT name
               FROM employees
               WHERE department_id IN (1, 2, 3);


           (j) BETWEEN
           The ‘BETWEEN’ operator selects values within a given range. For example,

               SELECT name, salary
               FROM employees
               WHERE salary BETWEEN 650000 AND 1250000;


           (k) LIKE
           The ‘LIKE’ operator is employed to find a particular pattern within a column. For
           example,
               SELECT name

               FROM employees
               WHERE name LIKE ‘J%’;

           The pattern ‘J%’ in the WHERE clause selects names from the employees table where
           the name column starts with ‘J’. Using ‘%’, a wildcard, matches any characters in
           SQL queries. Thus, this query retrieves all names starting with ‘J’.

                                                 474
                                                                for Advanced Secondary Schools



     Computer Science Form 5.indd   474                                                     23/07/2024   12:35
   478   479   480   481   482   483   484   485   486   487   488