One of the most important tasks when using a database is to search and retrieve information. When you create a database, sometimes large tables (though necessary) don't make your life easy. You need to reorganize your data from the many tables so that necessary information can be gathered for easy viewing and manipulation.
Definition:
A query is a piece or part 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.
Creating A Query From A Wizard:
- Start Microsoft Access and open the MPLS1 database. A query can be created from one table, more than one table, or from another query. Like a table, a query can be created in many different ways, except that, this time, data originates from somewhere, mainly a table.
- To create our first query, From the Database window, click the Queries button. Double-click the Create Query By Using Wizard button. (If you are using MS Access 97, click New, click Simple Query Wizard, and click OK).
- The first page of the Simple Query Wizard expects you to choose the origin of your query, starting with the table or the query name. For this example, we will use the tblEmployees table.
- Then, you choose the necessary data that you want to filter for your query. We want to use this query to easily retrieve the employees data by either their employee number, their last name, the date they were hired, their salary, their marital status, their E-Mail address, or the city or state they live in. All other information can be used somewhere else. From the Available Fields list box, double-click EmployeeNumber, Title, LastName, Function, DateHired, Salary, MaritalStatus, City, and State. Click Next twice.
- Give the title qryEmployees to your query. Click Finish. The finished product looks like a spreadsheet, made of columns and rows. Unlike the parent table, it contains only the data we want to query.
- Now that we have a query, it is time to put it to good use. You can modify criteria or the behavior of a query in Design View. Switch to the Design View.
- Under the LastName field, set the Sort orders to Ascending.
When your query is ready, you can run it by clicking the exclamation button
on the toolbar.
- To see the results of our query, click the exclamation point button on the standard toolbar.
- Switch back to Design View. Delete the Ascending sort the LastName field
- To view employees by seniority in the company, sort the employees in ascending order under DateHired. And run the query.
- Now, to see the last employee who was hired and other subsequent employees, change the sort to Descending, under DateHired. Then run the query.
- Switch to Design View and delete the sort retrieval under DateHired.
- To see the lowest paid employee in the company, set the sort retrieval to Ascending under Salary. Then run the query.
- When you are finished inquiring about other people's salary, switch to Design View, and delete the sort set under Salary.
- You can run a double query. For example, if you want to find out people by seniority (who was hired first in a certain year), and you want to find out who is earning more among those hired in a time period, set the sort retrieval under DateHired to Ascending; then set the sort to Descending under Salary. And run the query.
- Switch to Design View. And delete both sort retrievals.
- Even after you have decided on the fields necessary for your query, you can decide not to take into consideration a field or some of the fields in your query. To do that, you would decide not to Show a field. To see how it is done, click the Show check box under MaritalStatus (so, make sure it is empty/unchecked). Then run the query. The Marital Status column is absent.
- Switch back to Design View and click the check box to Show the MaritalStatus field.
No comments:
Post a Comment