Queries with Multiple Criteria (OR) When a query has multiple criteria, logical operators such as AND or OR combine the criteria together. This exercise has two example questions to illustrate, in two different cases, the use of the OR operator to combine criteria. The OR logical operator specifies that just one criteria is true or both criteria are true for a record to display when you run the query.
Queries with Multiple Criteria (OR) If necessary: Start Microsoft Access. Open the database file Queries from your Exploring Access folder.
Question 1 Multiple Criteria, Same Field, Logical OR Operator Just read this slide! Question 1 illustrates: A multiple criteria query. The criteria are for the same field. The criteria are combined with the OR operator. Question 1: List all of the products whose units in stock is less than 20 or greater than 100 using the ProductName, UnitsInStock, and UnitPrice fields of the Products table. Save this query as Products with Few or Many in Stock.
Question 1 Multiple Criteria, Same Field, Logical OR Operator Click the Query Design button in the Queries group on the CREATE tab of the ribbon bar.
Question 1 Multiple Criteria, Same Field, Logical OR Operator To add the Products table to the query window. Double-click the Products table.
Question 1 Multiple Criteria, Same Field, Logical OR Operator Click the Close button to close the Show Table dialog box.
Question 1 Multiple Criteria, Same Field, Logical OR Operator Double-click the ProductName, UnitsInStock and UnitPrice fields in the Products table window. To add these fields to the query s design grid.
Question 1 Multiple Criteria, Same Field, Logical OR Operator Both criteria are written for the UnitsInStock field. The 1 st criteria for Question 1 is: <20 The 2 nd criteria for Question 1 is: >100 Because both criteria are written for the same field, the two criteria are combined using the OR operator as such: <20 Or >100
Question 1 Multiple Criteria, Same Field, Logical OR Operator Type <20 Or >100 in the first Criteria row of the UnitsInStock column.
Question 1 Multiple Criteria, Same Field, Logical OR Operator The criteria for Question 1 reads as: UnitsInStock < 20 or UnitsInStock > 100
Question 1 Multiple Criteria, Same Field, Logical OR Operator Click the Save button on the Quick Access Toolbar.
Question 1 Multiple Criteria, Same Field, Logical OR Operator Type Products with Few or Many in Stock in the Query Name textbox. Click the OK button to save the query.
Question 1 Multiple Criteria, Same Field, Logical OR Operator The completed query.
Question 1 Multiple Criteria, Same Field, Logical OR Operator Click the Run button in the Results group of the DESIGN tab in the QUERY TOOLS section of the ribbon bar.
Question 1 Multiple Criteria, Same Field, Logical OR Operator When you run this query, it displays all the products (Product records) 1. whose units in stock is less than 20, OR 2. whose units in stock is greater than 100. According to logic, if both operands of the OR operator are true, then the result of the OR is true. But, for the use of OR in this query, it is impossible for both criteria to be true for a record to display in the query. Go to the next slide to see the records displayed for this query.
Question 1 Multiple Criteria, Same Field, Logical AND Operator Close the query.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator Just read this slide! Question 2 illustrates: A multiple criteria query. The criteria are for different fields. The criteria are combined with the OR operator. Question 2: List all of the books that are published after 1996 or whose list price is greater than or equal to 40 dollars using the Title, Year, ListPrice and Publisher fields of the Books table. Save this query as New or Expensive Books.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator Click the Query Design button in the Queries group on the CREATE tab of the ribbon bar.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator To add the Books table to the query window. Double-click the Books table.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator Click the Close button to close the Show Table dialog box.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator If necessary, increase the height of the Books table window to view all the fields. Double-click the Title, Year, ListPrice and Publisher fields in the Books table window. To add these fields to the query s design grid.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator The Year criteria for Question 2 is: >1996 The ListPrice criteria for Question 2 is: >=40 Because each criteria is written for a different field, the two criteria can not be combined using the word OR. To combine both criteria with the OR operator: Each criteria is written in a criteria row for its field. Each criteria must be written on a different row.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator Type >1996 in the first Criteria row of the Year column.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator Type >=40 in the second Criteria row of the ListPrice column.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator The criteria for Question 2 reads as: Year > 1996 or ListPrice >= 40
Question 2 Multiple Criteria, Different Fields, Logical OR Operator Click the Save button on the Quick Access Toolbar.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator Type New or Expensive Books in the Query Name textbox. Click the OK button to save the query.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator The completed query.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator Click the Run button in the Results group of the DESIGN tab in the QUERY TOOLS section of the ribbon bar.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator When you run this query, it displays all the books (Book records) 1. whose year is greater than 1996, OR 2. whose list price is greater than or equal to 40 dollars, OR 3. whose year is greater than 1996 and list price is greater than or equal to 40 dollars. According to logic, if both operands of the OR operator are true, then the result of the OR is true. Number 3 above is this case and for the use of OR in this query, it is possible for both criteria to be true for a record to display in the query. Go to the next slide to see the records displayed for this query.
Question 2 Multiple Criteria, Different Fields, Logical OR Operator
Question 2 Multiple Criteria, Different Fields, Logical OR Operator Close the query. Close the database file and Microsoft Access.