Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Systems Microsoft Access Practical #3 Queries Nos 215.

Similar presentations


Presentation on theme: "Database Systems Microsoft Access Practical #3 Queries Nos 215."— Presentation transcript:

1 Database Systems Microsoft Access Practical #3 Queries Nos 215

2 Queries You use queries to view, change, and analyze data in different ways. You can also use them as a source of records for forms, reports, and data access pages. There are several types of queries in Microsoft Access. –Select Queries –Parameter Queries –Crosstab Queries –Action Queries –SQL Queries

3 Select Queries The simplest type of query is a select query that will let you select certain data based on criteria you provide This is the query that will come up if you choose “Create query by wizard” It retrieves data from one or more tables and displays the results in a datasheet where you can update the records sometimes You can also use a select query to group records and calculate sums, counts, averages, and other types of totals.

4 Select Queries If you create a query by wizard, you will see the familiar screen letting you choose what you want to include in your query The next screen will ask for “Detail” or “Summary.” Detail will put all the information in your results. Summary will let you summarize different field types. For example, you can take the average of all the ages instead of displaying just the age of a person. Then when you are done with the wizard, you will see the datasheet with the data you selected

5 Select Queries: Design View So to get the good functionality out of Access we need to look at the Design view of the query. The design view will show tables at the top half (you can add more by right clicking and going to ‘Show Table’) Then you can drag fields you want to appear to the bottom. The bottom contains all the fields in your query and whether you want to show them. You can also sort based on certain ordering here

6 Select Query: Criteria There will also be many times when you want to select items based on different criteria (Example, select all people with name of sione) If this is the case, you can add in stuff in the criteria field on the bottom of the design view For example, if you have a field called names and you just want to see “Sione,” inside the Criteria field, you will put = “Sione” This works for other cases, like if you have a field called age and you want all the people over 50, put > 50

7 Action Queries An action query is a query that makes changes to or moves many records in just one operation. There are four types of action queries: –Delete – a query to delete a number of records –Update – a query to update records –Make-Table – create a new table from parts of other tables –Append – add records from one table to the end of another table.

8 Action Queries To make an action query, go to the design view and select one of the actions (delete, update, append, make-table) from the Query menu If you choose “Update” for example, the parts below will be changed to have an “Update to” field appear. This is where you can put in a new value that the records will be updated to If you choose “Delete” a “Delete” field will appear. It will say “Where” and this lets you add criteria. So to delete all people over fifty, you would add in the criteria field > 50

9 Action Queries Append – By choosing an append query you can add records from one table to the end of another. When you choose it, a new window will appear asking for where the data will be appended to Then you can construct a query, and the results of that query will be put into the table you have chosen. This can be helpful if you have another database and you need to put the data in, but don’t want to type everything Finally, when you are done making your query in design view, make sure to hit the “!” button to make it run.

10 Crosstab Queries You use crosstab queries to calculate and restructure data for easier analysis of your data. Crosstab queries calculate a sum, average, count, or other type of total for data that is grouped by two types of information — one down the left side of the datasheet and another across the top. They are just a different way to display data that limits the presentation to three categories (the row header, the column header and the values)

11 Crosstab Queries To create a crosstab query, you can start with your standard query and then go to design view. Then select from the Query menu, Crosstab. Another row on the bottom level will appear that says “Crosstab” Here is where you will select one row, one header and one column that will contain the values. For example, if you had a table of family members and you wanted to see their ages grouped by their name and their gender: –Select name as the Row Header, Gender as Column Header, age as Values

12 Crosstab Queries Crosstab queries are also a good way to see calculations on data. When you select a field as the “Values” you can also change how the data is computed from the line that says “Total” The column and the row headers will say “Group by” and you are able to change the Value field to Sum, Min, Max, Avg and so on. If you have data that is similar and can be grouped together, the Value field will then be displayed as a composite of all the Values that match

13 Parameter Queries A parameter query is a query that, when run, displays a box prompting you for information, such as criteria for retrieving records or a value you want to insert in a field. You can design the query to prompt you for more than one piece of information; for example, you can design it to prompt you for two dates. Microsoft Access can then retrieve all records that fall between those two dates. Parameter queries can also be good for reports and forms that ask the user for a certain of data to be entered.

14 Parameter Queries To create a parameter query, click in the criteria section and enter an expression that will be used by the query Examples –To make the user enter a name to select by, put in the criteria field = [Enter Name:] –To make the user enter an age that will be greater than all the ages selected < [Enter Maximum Age:] The general rule is that you put the symbol you want to compare against (=,>,<, LIKE, etc), then, inside brackets, put the message you want to appear

15 Parameter Queries Suppose you had a date and you wanted the user to enter two dates to mark all the acceptable dates Inside the criteria field, we can put two dates with the following code: Between [Enter First Date:] and [Enter Second Date:] The dates the user enters will bound the select query

16 The Union Operator Just like in the theory part of the class, there is a real world Union operator. It will take two tables and combine all their fields into one beautiful table Go to the Query menu, then SQL Specific and then choose Union. A window will appear that will be blank. Unfortunately, we have to paste in or write SQL queries here. What we can do is make two queries, then paste them in and put “union” between them. The result will be a new table with both values

17 Union Simple union example. –Say we had two tables. One is mothers, the other is children. –First we make a query to select the name and age select name,age from Mothers –Then we make a query to select name and age from Students select name,age from Students –Now we take them both and put them in the Union window –select name,age from mothers UNION select name,age from Students The result will be one big table

18 SQL Queries Most of the queries you create with the Wizard or design have counterparts in the SQL language. In fact, all your queries are turned into the SQL language before they are actually executed. You can see what the SQL code is for any query after you create it by clicking on SQL View in the View menu. You are also able to create your own SQL queries in here, which you can do once we learn the language.


Download ppt "Database Systems Microsoft Access Practical #3 Queries Nos 215."

Similar presentations


Ads by Google