Download presentation
Presentation is loading. Please wait.
Published byShonda Cannon Modified over 8 years ago
1
Lesson 4: Querying a Database
2
2 Learning Objectives After studying this lesson, you will be able to: Create, save, and run select queries Set query criteria and sort order Create and format a calculated field Use functions in query expressions Create special types of queries
3
Reviewing Query Features 3 A query acts as a saved question you ask a database. A query is a subset of data from one or more tables. Data displayed in query results remain stored in the original table rather than in the query. When you edit data in query results, you are actually editing the data stored in the source table.
4
Reviewing Query Features 4 Queries are dynamic objects that display up-to-date data stored in database tables. Queries can be used to create forms and reports, which may contain fields from multiple tables. Query results datasheets enable you to filter or selectively organize data using the same techniques you may use to filter and organize table datasheets.
5
Creating Select Queries The most common type of query is the select query. Access contains two distinct tools for creating select queries: Query Wizard Query Design 5
6
Using the Simple Query Wizard Steps you through the creation of a select query Enables you to identify table(s) and fields from each table that you want to include in the query Prompts you to save the query 6
7
Using Query Design View Presents a split window with table field lists at the top and columns and rows at the bottom 7
8
Adding Fields to the Query Grid Double-click a field name to add the field to the next available column of the query design grid. Drag a field to the next column in the grid. Click the Field row of a column in the query grid and select the field from the drop-down list. Double-click the asterisk (*) that appears at the top of the field list to add all fields to the grid. Double-click the field list title bar to place each field in the table in a separate column of the query grid. 8 Note! When you use the asterisk to add all fields, Access places the table name in the Field row, but when you run the query, each field appears in a separate column of the query results datasheet.
9
Adding Fields to the Query Grid You can rearrange query columns in Design View or Datasheet View by dragging and dropping them into position. 9
10
Multi-Table Query When you add fields from multiple tables, these tables must be related in order for the intended results to be displayed. You may wonder which ID field to add to a query. The best practice is to identify the table for which the ID field is the primary key. 10
11
Setting Query Criteria 11 Comparison Operator Wildcard Value Dates Wildcard
12
Setting AND and OR Criteria AND Criteria OR Criteria 12
13
Sorting a Query and Limiting Results Sorting query results Use sort tools after running the query. Set a sort order in the query grid Sort row. 13
14
Limiting Results Effective way of limiting results; combines sorting with restricting the number of results to display The Return feature on the Query Design tab enables you to set the number of records you want to retrieve. 14
15
Performing Calculations in Queries A calculated field: Creates a new field in the query that can be used in a form or report Can be used to perform mathematical operations such as add and multiply Has a name and can be formatted with properties just like a regular field Enables you to combine values in two text fields into one field, such as LastName and FirstInitial Updates and recalculates each time you run the query 15
16
Calculated Fields Have no value of their own Perform calculations using other field values Calculated field name Field names from existing tables Arithmetic or comparison operator 16
17
Please Excuse My Dear Aunt Sally Parentheses Exponentials Multiplication/Division Addition/Subtraction (2+2)*32=6/2=33 17
18
Using Functions in Queries Aggregate functions perform specific calculations, such as finding the minimum, maximum, and average values, and counting and summing the entries in a datasheet. 18
19
Crosstab Queries Rearrange data for summarizing Group data and total values 19
20
Crosstab Query Palette Groupings appear as row and column headings. Summarized values appear in the TOTAL area. 20
21
Unmatched and Duplicates Queries Check database tables to ensure there is no duplication of records Also check database to ensure that records referenced in one table have a matching record in the other table Hoped-for result of running these two queries is that Access finds nothing to report. 21
22
Structured Query Language SQL is the underlying structure created for queries in Access. 22
23
Lesson 4: Querying a Database
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.