Page 35 - Computing Book 8
P. 35

Handling Databases                                                                   Class 8


               Create Simple and Complex Queries:

               Database tables can hold a lot of records, in some cases, millions or billions of them, therefore, if you
               want to find a piece of information, you have to filter the records and select which ones you want to
               display. To do that, you have to create a query. A query is a special “question” you apply to the
               database to find specific data and get the information you want. For this task, let’s continue working
               with the Employee table we have used before.

               Creating a Query:

               •  Click on the Query Design option from the create tab.
               •  A new window will open with the name of Show Table.
               •  Select and add tbleEmployee and tblHRData.
               •  Let us suppose that we need the data of our
                   employees with their first name, last name and
                   their salaries which are higher than 3500$.
               •  For the first column select the employee’s first
                   name.
               •  In the second column select employee’s last
                   name.
               •  In the third column select StartSalary.
               •  We can get the data from both tables accurately
                   as both table’s EmployeeID fields are related to
                   each other using PK and FK.
               •  After selecting the fields for a query, you can see
                   the name of fields and other options for Sort and
                   setting a criterion.
               •  Select the Ascending option from the first column
                   (FirstName).
               •  In the third column enter the criteria for salaries
                   as preferred. In the example, we have entered
                   >3500. Which means that employees who have
                   salaries greater than 3500 will be listed in
                   ascending order after executing the queries.
               •  Save the query by using the right click on the
                   query tab and save it with any preferred name. In
                   the example, we have saved the query with the
                   name of Salaries Greater than 3500.
               •  Close the tab and run the query from the objects
                   panel.
               •  In the next example, we assume that we need the
                   list of employees who have joined after the year
                   2018.
               •  We will add the preferred columns along with the
                   field of HireDate from tblHRData.
               •  And enter the criteria as >12/30/2008 and press enter.



               The City School /Academics/Computing Curriculum/Class 8/2020-2021                Page 34 of 75
   30   31   32   33   34   35   36   37   38   39   40