4 Session4 Queries

Embed Size (px)

Citation preview

  • 7/30/2019 4 Session4 Queries

    1/19

    access session 4

    Using Queries to Select Data

  • 7/30/2019 4 Session4 Queries

    2/19

    Database Operation in Table Datasheet view Retrieve, sort and group data

    Limit results

    Evaluate expressions

  • 7/30/2019 4 Session4 Queries

    3/19

    Table Datasheet view Operations(Sort and Filter)

    how to. Records menu

    Table Datasheet toolbar

    Filter by Selection Excel concept ofAutoFilter

    Filter by Form Excel concept of Custom

    Filter

  • 7/30/2019 4 Session4 Queries

    4/19

    Comparison and Logical Operators

    Comparison Logical= Equals

    OrMeets any onecondition> Greater than

    >= Greater than or equal And Meets allconditions< Less Than

  • 7/30/2019 4 Session4 Queries

    5/19

    Query Preliminaries

    Queries are used to sort, filter, add, delete,and modify data in MS Access databases

    use queries to request data for forms,

    reports, and controls when an object relieson specific data rather than on all the datain the underlying table.

  • 7/30/2019 4 Session4 Queries

    6/19

  • 7/30/2019 4 Session4 Queries

    7/19

  • 7/30/2019 4 Session4 Queries

    8/19

    Query Types 1/2

    Select: retrieve data that meets specificconditions, group records for viewingsummary data, and display calculations

    performed on data fieldsAction: modify existing data in some way,

    used to delete, update, and append data orto create a new table.

  • 7/30/2019 4 Session4 Queries

    9/19

    Query Types 2/2

    Parameter: prompt you for criteria beforerunning the actual query

    Crosstab: summarize data and then groupthe summarized values into categories

    SQL: include union, pass-through and data-definition queries, require specific SQLcommands, that you must compose in SQL

    view

  • 7/30/2019 4 Session4 Queries

    10/19

    the query environment

    query Design view: identify the tables and queriesthat you want to include in your query. and create& view queries

    field list: upper part window displays a field list for each

    table or query design grid: lower part window, define the querys fields

    and accept expressions as criteria for limiting the resultsof the query

  • 7/30/2019 4 Session4 Queries

    11/19

    SQL view: translated query design view intoJet Structured Query Language.

  • 7/30/2019 4 Session4 Queries

    12/19

    Common SQL keywords

    AS: creates a clause that specifies an expressionor value and the field name associated with it

    DISTINCTROW: exclude duplicate records from

    the query FROM: Create a clause specifying the table or

    query from which fields are taken for the query

    ORDER BY: Crates a clause containing a list offields to be included in the query

  • 7/30/2019 4 Session4 Queries

    13/19

    SELECT: creates a clause containing a listof fields to be includes in the query

    UNION: Combines two sets of records into

    a single set WHERE: Creates a clause with a condition

    (or set of conditions) for filtering query

    records.

  • 7/30/2019 4 Session4 Queries

    14/19

    The Simple Query wizard Summarizing Data using the Wizard

    Retrieving Data using the Design view

    1. click new, then add fields from the Show tablewindow

    2. execute the query using the Run button from

    the Query Design toolbar

  • 7/30/2019 4 Session4 Queries

    15/19

    5 methods for adding fields to thedesign grid

    double-click the field in the field list drag the field to a column

    double-click or drag the * in the field list

    field drop-down list

    type the field name in a columns Field cell

  • 7/30/2019 4 Session4 Queries

    16/19

    other design grid components

    Sorting Records: using the Sort cell Computing totals for group records: using

    Group by Drop-down list (view menu,

    totals) Limiting Data: using the Criteria or Or cell

  • 7/30/2019 4 Session4 Queries

    17/19

    Crosstab

    Crosstab query is a query that groupssummarized data by categories, a morecompact way to group and summaries record

    Crosstab vs PivotTable both summarize data using aggregate functions

    PivotTables are more powerful because they candisplay the detailed data behind those subtotals and

    grand totals without affecting the groups

  • 7/30/2019 4 Session4 Queries

    18/19

    Crosstab vs PivotTable (cont.) column headings: PivotTables (multiple) while

    Crosstab (one)

    PivotTables also include crossfoot totals,Crosstab none

    PivotTables: quicker to produce and moreflexible that crosstab queries

  • 7/30/2019 4 Session4 Queries

    19/19

    To sum it up

    datasheet sorting & filtering vs. queries Both can be manipulated using the design grid

    area

    Queries: saved objects Manipulate the query design view, design

    grid area