queries that select records chapter 6 7 n.
Skip this Video
Loading SlideShow in 5 Seconds..
Queries That Select Records (Chapter 6 – 7) PowerPoint Presentation
Download Presentation
Queries That Select Records (Chapter 6 – 7)

Loading in 2 Seconds...

play fullscreen
1 / 42

Queries That Select Records (Chapter 6 – 7) - PowerPoint PPT Presentation

  • Uploaded on

Queries That Select Records (Chapter 6 – 7). Query Basics. A Microsoft Access query is a question about the information stored in Access tables .

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about 'Queries That Select Records (Chapter 6 – 7)' - eve-moses

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
query basics
Query Basics
  • A Microsoft Access query is a question about the information stored in Access tables.
  • Your query can be a simple question about data in a single table, or it can be a more complex question about information stored in several tables.
  • After run query, Microsoft Access returns only the information you requested.
creating queries in design view
Creating Queries in Design View
  • The best starting point for query creation is the Design view.
    • Choose Create  Queries  Query Design.
    • Select the table that has the data you want, and then click Add  Click Close.
creating queries in design view1
Creating Queries in Design View
  • Select the fields you want to include in query.
  • Arrange the fields from left to right in the order to appear in the query results.
  • If you want to hide one or more columns, then clear the Show checkbox for those columns.
creating queries in design view2
Creating Queries in Design View
  • Choose a sort order.
  • Set your filtering criteria by place the expression into the Criteria box for the appropriate field.
  • Choose Query Tools Design  Results  Run. Save the query.
getting the top records
Getting the top records
  • Use the Top Values box on the Design View toolbar to see the top records produced by the query.
    • Open query in Design view.
    • Sort table so that the records you’re most interested in are at the top.
    • In the Query Tools  Design
    • Query Setup  In return box,
    •  choose a different option
creating queries by wizard
Creating Queries by Wizard
  • Create a simple Query by using wizard.
  • The Query wizard works by asking you a series of questions.
    • Choose Create  Queries  Query Wizard.
creating queries by wizard1
Creating Queries by Wizard
  • Choose a query type. The Query wizard includes a few common kinds of queries.
    • Simple Query Wizard.
    • Crosstab Query Wizard.
    • Find Duplicates Query Wizard.
    • Find Unmatched Query Wizard
  • OK.
  • In the Tables/Queries box, choose the table that has the data you want.
creating queries by wizard2
Creating Queries by Wizard
  • Add the fields you want to see in thequery results
  • Click Next. Enter query name  Click Finish.
understanding the sql view
Understanding the SQL View
  • Behind the scenes, every query is actually a text command written in a specialized language called SQL (Structured Query Language).
  • To take a look at the SQL command for a query, right-click the tab title, and then choose SQL view.
  • Example:

1 SELECT Products.ID, Products.ProductName, Products.Price

2 FROM Products

3 WHERE (((Products.Price)>50))

4 ORDER BY Products.Price;

understanding the sql view1
Understanding the SQL View
  • Every query has common ingredients (thànhphần), represented by:
    • SELECT: list of fields appear in the query results.
    • FROM: indicates the table (or tables) that you’re searching.
    • WHERE: indicates the start of your filter conditions.
    • ORDERBY: define the sorting order.
queries and related tables
Queries and Related Tables
  • A join line connects tables in the query design. The join line connects the primary key in one table to the foreign key in another table.
  • By default, an Access query returns only records where data exists on both sides of a relationship.
  • To see records that are not matched on the other side of the join. You must modify the default query join.
queries and related tables1
Queries and Related Tables
  • Can create joins between tables in these three ways:
    • By creating relationships between the tables when you design the database.
    • By selecting two tables for the query that have a field in common that has the same name
    • By modifying the default join behavior
calculated fields
Calculated Fields
  • To create a calculated field, you need to supply two details:
  • Example: define the PriceWithTax calculated field:

PriceWithTax: [Price] * 1.10

Field Name : Expression

Field Name


simple math with numeric fields
Simple Math with Numeric Fields
  • Simple Math with Numeric Fields
expressions with text
Expressions with Text
  • To join text, use the ampersand (&) operator.
  • For example:
    • Create a FullName field from the FirstName and LastName fields:

FullName: [FirstName] & “ “ & [LastName]

    • To “The price is” to appear before each price value, use this calculated field:

Price: "The price is: " & [Price]

query functions
Query Functions
  • A function is a built-in algorithm that takes some data that you supply, performs a calculation, and then returns a result.
  • Functions is used in:
    • Calculated fields. To add information to your query results.
    • Filter conditions. To determine what records you see in a query.
    • Visual Basic code.
using a function
Using a Function
  • To use a function:
    • Enter the function name, followed by parentheses.
    • Inside the parentheses, put all the information the function needs in order to perform its calculations.


SalePrice: Round([Price] * 0.95, 2)

the expression builder
The Expression Builder
  • To quickly find the functions you want, Access provides a tool called the Expression Builder.
  • To launch the Expression Builder:
    • Open aquery in Design view.
    • Right-click the box where you want to insert your expression, and then choose Build.
    • Add oredit the expression.
    • Click OK.
the expression builder1
The Expression Builder
  • To find a function:
    • Expand the Functions item, and choose Built-In Functions.
    • Next, choose a function category in the Expression Categories list.
    • The Expression Values list will show all the functions in that category.
    • Double click on functions name to insert it into your expression.
formatting numbers1
Formatting Numbers
  • Format(): mathematical function that transforms numbers into text.
  • Example:

SalePrice: [Price] * 0.95

    • Use the Format() function to apply a currency


SalePrice: Format([Price] / 0.95, "Currency")

  • More Mathematical Functions (Page 230)
  • Text Functions (Page 232)
  • Date Functions (Page 234)
summarizing data
Summarizing Data
  • Total function is used to group the records to arrive at totals and subtotals. That way, you can review large quantities of information much more easily.
  • Example:
    • Counting all the students in each class.
    • Counting the number of orders placed by each customer.
    • Totaling the amount of money spent on a single product.
summarizing data1
Summarizing Data
  • These operations are used to summarize data:
    • Count
    • Sum
    • Average
    • Max
    • Min
summarizing data2
Summarizing Data
  • Create a totals query:
    • Createa new query by choosing Create➝ Queries ➝ Query Design.
    • Add the tables you want to use fromthe Show Table dialog box, and then click Close.
    • Add the fields you want to use.
    • Choose Query Tools Design  Show/Hide Totals.
summarizing data3
Summarizing Data
  • For each field, choose an option from the Total box. This option determines whether the field is used in a calculation or used for grouping.
  • Every field must belongto one of these categories:
    • It’s used in a summary calculation (like averaging, counting, …).
    • It’s used for grouping.
    • It’s used for filtering.
summarizing data5
Summarizing Data
  • Example: Calculate Total for every Order
query parameters
Query Parameters
  • Query parameters let you create flexible queries by enter one pieces of information.
  • Every time you run the query, Access prompts you to supply the missing values. These missing values are the query parameters.
  • Usually, query parameters are used in filter conditions.
  • When run the query, you fill in the value you want to use at that particular moment.
query parameters1
Query Parameters
  • To create a query that uses parameters:
    • Create a new query by choosing Create  Queries  Query Design.
    • From the Show Table dialog box, add the tables you want to use.
    • Choose Query Tools Design Show/Hide  Parameters. The Query Parameters dialog box appears.
    • Choose a name and data type for parameter.
    • Click OK to close the Query Parameters dialog box.
crosstab queries
Crosstab Queries
  • A crosstab query is a powerful summary tool that examines huge amounts of data and uses it to calculate information like subtotals and averages.
  • Crosstab queries use two key ingredients: grouping and summary functions.
    • The grouping is used to organize the rows into small sets.
    • The summaryfunction is used to calculate a single piece of information for each group.
crosstab queries1
Crosstab Queries
  • Creating Crosstab Queries: have two ways to create a crosstab query:
    • The Crosstab Query Wizard provides an automated way to create a Crosstab query. The wizard works only with one table or query.
    • Build Crosstab Query by hand.
crosstab queries2
Crosstab Queries
  • Creating a Crosstab Query with the Wizard
    • Display the Create tab on the Ribbon.
    • Click the Query Wizard button in the Macros & Code group on the Ribbon.
    • The New Query dialog box opens.
    • Select the Crosstab Query Wizard option and then click OK.
    • Select the table or query that contains all the fields you need for your Crosstab query, and then click Next.
crosstab queries3
Crosstab Queries
  • Select the field(s) whose values you want to use as row headings  click Next.
  • Select the field(s) whose values you want to use as column headings  click Next.
  • If select a date field as the column headings, Choose how to group dates from the list Next.
  • Choose the field whose values grouped by the row and column headings that are selected.
crosstab queries4
Crosstab Queries
  • Select a grouping method from the Functions list.
  • Choose whether to include row sums by selecting the check box on the same page as the function choices, and then click Next.
  • Name the query and then click Finish to see the Crosstab query.
crosstab queries5
Crosstab Queries
  • Creating a Crosstab query in Design view: A simple Crosstab query has three fields:
    • One used for row headings
    • One used for column headings.
    • The Value field, which contains the data that you want to appear in the cells of the table. Tell Access how to summarize your data in the Crosstab query by choosing from these choices: Sum, Avg, Min, Max, Count, StDev, Var, First, or Last.
crosstab queries6
Crosstab Queries
  • Choose Create ➝ Queries ➝ Query Design.
  • Add the table or query you want to use in crosstab query.
  • Query Tools  Design Query Type  Crosstab.
  • Choose the fields use for row labels and in the Crosstab row, choose the Row Heading.
  • Choose the fields use for Column labels and in the Crosstab row, choose the Column Heading.
crosstab queries7
Crosstab Queries
  • Select the field containing the values that you want aggregated, in the Crosstab row, choose the Value option.
  • Set the Total row:
    • Group By option for column heading and row heading.
    • Choose summarize the data for the Value field column.