Page 482 - Computer_Science_F5
P. 482

(b) JOIN
              The ‘JOIN’ clause merges rows from multiple tables by using a common column
              that links them. For example,
                  SELECT employees.name, departments.department_name
                  FROM employees                                                                   Chapter Eight: Databases and Database Management Systems
          FOR ONLINE READING ONLY
                  JOIN departments ON employees.department_id = departments.department_id;

              (c) WHERE
              The ‘WHERE’ clause is used to filter records. For example,

                  SELECT name, age
                  FROM employees
                  WHERE age > 50;

              (d) ORDER BY
              The ‘ORDER BY’ clause sorts the result set in either ascending or descending order.
              For example,
                  SELECT name, salary
                  FROM employees
                  ORDER BY salary ASC;

              (e) GROUP BY
              The ‘GROUP BY’ clause organises rows with identical values in specified columns
              into summary rows. For example,
                  SELECT department_id, COUNT(*)
                  FROM employees
                  GROUP BY department_id;

              COUNT(*) in this statement, tallies the number of records associated with each
              unique department_id  in the employees  table,  summarizing  the  total  rows per
              department_id group. This query outputs a list of department_id values alongside
              the corresponding count of employees within each department.

              (f) HAVING
              The ‘HAVING’ clause was introduced in SQL to enable filtering based on aggregate
              functions, which  the ‘WHERE’ keyword cannot do. For example,
                  SELECT department_id, COUNT(*)
                  FROM employees

                  GROUP BY department_id
                  HAVING COUNT(*) > 10;

                                                    473
               Student’s Book  Form Five



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