Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS&E 1111 AcQueries Writing Simple Queries in Access Displaying on specific data fields Filtering data using criteria Objectives: Learn how to use the.

Similar presentations


Presentation on theme: "CS&E 1111 AcQueries Writing Simple Queries in Access Displaying on specific data fields Filtering data using criteria Objectives: Learn how to use the."— Presentation transcript:

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

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

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

4 CS&E 1111 AcQueries Writing a Criterion Criteria is a collection of criterion or conditions: l 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 CS&E 1111 AcQueries Foreign Key Primary Key Products: Suppliers: Consider the following database :

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

7 CS&E 1111 AcQueries The resulting dynaset: What happens if we later change the units in stock for Mini- cookies on the Products Table an re-run the query?

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

9 CS&E 1111 AcQueries The data table: The resulting dynaset:

10 CS&E 1111 AcQueries Relational operators in a query: =, =, <>, l With Numbers <= 10 values of less than or equal to 10 l 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 CS&E 1111 AcQueries List the product names for products with greater than 40 units in stock You can use relational operators in your criteria Products CategoryID ProductName Unitsinstock SupplierID ProductID Price

12 CS&E 1111 AcQueries The data table: The resulting dynaset:

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

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

15 CS&E 1111 AcQueries 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 “...” Products CategoryID ProductName Unitsinstock SupplierID ProductID Price

16 CS&E 1111 AcQueries For multiple conditions in the same field use 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 CS&E 1111 AcQueries List by product the units in stock for both categories BE and BA The “OR” operator for a single field’s conditions Products CategoryID ProductName Unitsinstock SupplierID ProductID Price

18 CS&E 1111 AcQueries The data table: The resulting dynaset:

19 CS&E 1111 AcQueries 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 Products CategoryID ProductName Unitsinstock SupplierID ProductID Price

20 CS&E 1111 AcQueries 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 Products CategoryID ProductName Unitsinstock SupplierID ProductID Price

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

22 CS&E 1111 AcQueries For conditions in multiple fields the placement of your arguments determines the Boolean relationship between those arguments: l If a criteria is on the same line it is automatically considered an AND l If criteria is on a separate line it is automatically considered an OR

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

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

25 CS&E 1111 AcQueries The data table: The resulting dynaset:

26 CS&E 1111 AcQueries 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 Products CategoryID ProductName Unitsinstock SupplierID ProductID Price Criterion on same line implies AND, Criterion on a separate line implies OR

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

28 CS&E 1111 AcQueries Summarizing Queries l A query is a set of instructions that specifies how to extract and organize data from a database l Access provides the QBE grid as a GUI interface to create the SQL code. l 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.


Download ppt "CS&E 1111 AcQueries Writing Simple Queries in Access Displaying on specific data fields Filtering data using criteria Objectives: Learn how to use the."

Similar presentations


Ads by Google