Querying

A query is a component of the database created to search for, and retrieve, specific data for a specific purpose. It can be viewed as a question, or a filter intended to select only some necessary data.

·        To create a query, click the Queries button. Double-click the Create Query By Using Wizard button.

·        The first page of the Simple Query Wizard expects you to choose the origin of the query. Let’s create a simple query to extract the names of all students enrolled in the course Physics-01 which has a course ID of 3.  Choose the Student table.

 

·        Then, you choose the fields from each table that you want to enter into the query. Click on the field you want to include and then click on . Choose SSN and Name

·        Next add the other table. Select the Takes table and include the SSN and CID fields of this table in the selected fields. Click on Next.

·        Click Next on the dialog accepting the default settings. The third dialog opens, give a title to the query, or choose the default name for this query. Click Finish.

·        The finished product looks like a table, made of columns and rows. It however contains only the fields we want to query.

 

·        Switch to design view by clicking on the Design View button. The top region displays the tables involved in the query, and any relationships between them.  The table at the bottom shows the field used, the tables they originated from, and any sorts and filters applied to them.

·        We want to display only the names of the students taking the course having CID = 3. Uncheck the show option of Student_SSN:SSN, Takes_SSN:SSN and CID. In the criteria field of CID, type in the following

“= 3”.

·        Save the changes made.

·        View the query in the datasheet view by clicking on Query in the main dialog and then double click on the query name.

                                       

Main | Prev | Next