1 / 28

Writing Simple Queries in Access

Objectives: Learn how to use the Access Query Design Tool to obtain specific information by -. Writing Simple Queries in Access. Displaying on specific data fields Filtering data using criteria. Querying : The process of asking the database for specific information

MartaAdara
Télécharger la présentation

Writing Simple Queries in Access

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. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Objectives:Learn how to use the Access Query Design Tool to obtain specific information by - Writing Simple Queries in Access • Displaying on specific data fields • Filtering data using criteria

  2. Querying : The process of asking the database for specific information • A specific format is used to ask these questions • The computer saves the format, not the results which can be generated upon demand (dynaset) • We will study the following types of queries: • Filtering data using single and multiple criteria • Sorting data • Grouping and summarizing data • Performing calculations on the data

  3. Query • A query is a question about the data in the database • Writing queries involves • Choosing the required tables • Where is your information coming from • Choosing the output fields • What information do you want to list • Choosing the criteria fields • What selection criteriado you want to specify -which records to “choose”

  4. Writing a Criterion Criteria is a collection of criterion or conditions: • Criterion - an expression that tells the DBMS which records to retrieve Criteria with 2 conditions: List records from category BE with more than 40 units in stock

  5. Consider the following database : Products: Suppliers: Primary Key Foreign Key

  6. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price Create a list of products by name and the number of units in stock for each No conditions

  7. The resulting dynaset: What happens if we laterchange the units in stock for Mini-cookies on the Products Table an re-run the query?

  8. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price List the products & units in stock for category BE Single condition criterion showing ProductName & Units

  9. The data table: The resulting dynaset:

  10. Relational operators in a query: = , <= , >= , <> , < , > • With Numbers <= 10 values of less than or equal to 10 • With Text < “G” text beginning with letters A through F > “Jones” text from Jones through end The appropriate expression is placed in the field where this data if found.

  11. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price List the product names for products with greater than 40 units in stock You can use relational operators in your criteria

  12. The data table: The resulting dynaset:

  13. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price List the product names and units in stock for products from the letters M to Z You can use relational operators in your criteria

  14. Wild cards in Criteria: • An asterisk * replaces any number of characters: • Like “C*” – in Product Name field will select c, Cookie, cake. • Like “*cookie*” - in Product Name field will select all records that include the word cookie in the Product Name field • A ? replaces a single character • Like “B?” – in the Category field will select BE & BA Would the criteria Like “432??” in the zipcode field select a record with the zipcode 43219-7888?

  15. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price List the product names for products that start with the letter M You can use wild cards in your criteria - just need to type m* the computer will add the syntax Like “...”

  16. For multiple conditions in the same fielduse Boolean Operators - AND,OR, NOT • “BE” Or “BA” >5 AND <10 • NOT “BE” • What dynaset would result from the criteria “BE” and “BA” in the category field? • No records would be selected since you cannot specify 2 mutually exclusive conditions with an And.

  17. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price List by product the units in stock for both categories BE and BA The “OR” operator for a single field’s conditions

  18. The data table: The resulting dynaset:

  19. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price List by product the units in stock for all products but those in category BE You can use the “not” operator for a single field’s conditions

  20. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price List the products & units in stock for all items with at least 20 units in stock but no more than 30 units in stock You can use the “AND” operator for a single field’s conditions

  21. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price List the products & units in stock for all items with at least 20 units in stock but no more than 30 units in stock An alternate syntax: >=20 and <=30 The between syntax allows you to set lower & upper limits - inclusively

  22. For conditions in multiple fields the placement of your arguments determines the Boolean relationship between those arguments: • If a criteria is on the same line it is automatically considered an AND • If criteria is on aseparate lineit is automatically considered anOR

  23. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price List product names for products in category BA with less than 30 units in stock The placement of both criteria on the same line implies an AND relationship

  24. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price List product names for products in category BA with less than 30 units in stock The placement of both criteria on the same line implies an AND relationship

  25. The data table: The resulting dynaset:

  26. Products CategoryID ProductName Unitsinstock SupplierID ProductID Price List product names for products in category BA with less than 30 units in stock or category BE with more than 31 units in stock Criterion on same line implies AND, Criterion on a separate line implies OR

  27. How does the computer store your query? • Access does not store the resulting table from your query - it simply stores the instructions to run the query • The actual SQL instructions can be seen in the VIEW menu • This is “memory efficient” since it does not require you to save all the information each time you want a different “view” of it. • It also insures that each time you use a query “view” you get the most current version.

  28. Summarizing Queries • A query is a set of instructions that specifies how to extract and organize data from a database • Access provides the QBE grid as a GUI interface to create the SQL code. • To properly use the QBE grid you must select the required data (table(s), query), the fields you wish to display and then specify the desired criterion, sorts, groupings and/or expressions.

More Related