Home

Logical Disjunction

 

The OR Operator

 

Introduction

Suppose a customer who is shopping, but is not ready, for a rental property comes to the office and states that she is considering renting. You show her the catalog of properties with apartments, townhouses, and single-family homes. At first glance, the customer says she cannot rent an apartment. The other two options are the townhouse or the single family. To prepare the new list, you must create a query that considers only these two options. Before building the query, you can state the following:

  • The property is a townhouse
  • The property is a single-family

We can start a truth table as follows:

The Property is a Townhouse The Property is a Single Family Result
     

To continue with this table, we can check each property. If the property is a townhouse, it is considered valid for our customer:

The Property is a Townhouse The Property is a Single Family Result
True Regardless True

It a property is not a townhouse. Then, we consider the next property. If the next property is a single family, it is also valid:

The Property is a Townhouse The Property is a Single Family Result
True Regardless True
Regardless True True

When building this table, we would skip a property only if it is neither a townhouse nor a single family. In Boolean algebra, this means that if both conditions are true, the whole statement is also true. The whole statement is false only if both conditions are false. This can be resumed as follows:

Condition 1 Condition 2 Result
True True True
True False True
False True True
False False False

This type of statement is referred to as logical disjunction. The logical disjunction is expressed in Microsoft Access and in SQL with the OR operator.

Logical Disjunction in Tables, Queries, and Forms

Once again, consider our list of videos:

Imagine that you want to see a list of the movies that either were released in 1994 or are rated PG-13. If a movie was released in 1994, the whole statement is true, regardless of the second condition. If a movie of our collection is rated PG-13, the whole statement is true even if the movie was released in a year other than 1994. The statement is also true if both conditions are met. On the other hand, if a movie was released in a year other than 1994 and it is not rated PG-13, then the whole statement is false.

As done for the logical conjunction, before applying a logical disjunction to a table, a query in Datasheet View or a form in Form View, first display it in Filter By Form:

While in the Look For tab, click the box under the column that would be used to set the first condition, and select the desired value:

After selecting the value of the first condition, click the Or tab in the lower left section of the window. Click the arrow of the combo box under the column that would be used as the second condition:

After setting the criteria, click the Apply Filter button:

 

Logical Disjunction in SQL Statements

When creating a query in Design View, the window provides two convenient sections for the first and the second conditions. To set the first condition, click the Criteria box corresponding to its column and type the operation. To set the second condition, click the Or box corresponding to its column and enter the necessary condition. Here is an example:

 

Practical Learning Practical Learning: Applying the OR Operator in a Query

  1. In the Queries section of the Database window, right-click Inventory of Properties and click Design View
  2. To create a list of townhouse and single-family properties, in the Criteria box of PropertyType, type "Townhouse"
  3. Press the down arrow key and, in the Or box of the PropertyType, type "Single Family"
     
  4. To save the query, on the main menu, click File -> Save As...
  5. Type Townhouse and Single Family Homes as the name of the query and press Enter
  6. Switch the query to Datasheet View to see the result
     
  7. Close the query
 
 

Previous Copyright © 2005-2016, FunctionX Next