Penn State Home Page

Teaching and Learning with Technology

Teaching with Databases

  TLT Home : TLT Suggestions

Main Menu

LOCATION: HOME PAGE: SEARCH TIPS

Using Boolean Operator

This Page

  1. What's a Boolean Operator?
  2. AND Boolean Operator
  3. OR Boolean Operator
  4. NOT Boolean Operator
  5. Combining Operators

What's a Boolean Operator

A Boolean operator is a computer-programming term for conjunctions like, AND, OR, and NOT which can be used to construct more complex search conditions for a database. They are named after the 19th century mathemetician George Boole who developed Boolean algebra, usually seen in elementary logic classes. Many database applications refer to "Boolean Search" or "Boolean operators" on an advanced search screen, so the term is worth knowing.

The rest of this page will discuss the common operators and explain who they interact with databases in more detail.

Top of Page

The AND Operator

The AND operator is similar to using a set multiple keywords in that you are looking for items which fit both a first criterion and a second criterion.Why not just use multiple keywords then? Some databases have search forms which do not support multiple keywords, but require you to insert an "AND" between each item.

How can the AND operator be visualized? One way is to image that the search criteria are two circle - each which contain records for a certain criterion. The records an AND search retrieves are those which within both the circle for the first criterion and within the circle for the second criterion. In other words, the results would come from where the criteria intersect.

In the diagram below, an AND search for "rap music" and "Spanish" (i.e. Spanish rap music) is represented visually with a yellow circle for XX and a blue circle for XX. The green circle where the yellow and blue circles cross represent those items which are XX and XX.
Note: This type of diagram is also called a Venn diagram.

AND Crossed Circles Diagram

Venn Diagram for AND - Search Results are in green

File Maker Pro

To do an AND Find, select or fill in items from multiple fields. To do an AND search in the same field, enter multiple keywords.

Access

To do an AND search from a form, enter Filter mode and place keywords in multiple fields. To do an "AND" search in the same field, place search terms in quotes and put "AND" in between them. To do an AND search query, make sure to include "AND" in the query design.

Google

Google and other online search engine support Boolean searches in the "Advanced Search" options.To do an "AND" search:

  1. Go to Google and click Advanced Search (right of search box).
  2. Enter keywords in the first box "with all of the words."

Top of Page

The OR Operator

The OR operator selects records which fulfil the first criterion or the second criterion. Within the same set of data, the OR search will retrieve more records than the parallel AND search would. One reason you might want to use an OR operator is to search across synonyms (e.g. "Britain" or "United Kingdom"). An OR search might also be used to pull items with related concepts, like similar genres or similar time periods in history.

If you were to visualize an OR search, the circles for both search criteria would be colored the same because results could come from either circle (or even from the intersection where both are true). Here's a diagram representing a search for "meregue" or "salsa" (both styles of Latino music). Both circles are green because search results could be merengue only, salsa only or both merengue and salsa.
Note: This is also called a union of two criteria as opposed to an intersection of two criteria for the AND search.

Or diagram

Venn Diagram for OR - Search Results are in green

File Maker Pro

For an "OR" Find, do the following:

  1. Go into Find mode and enter the first search criteria into the form.
  2. Go the the Request menu and select Add New Request.
  3. Enter in the second search criteria. Repeat as often as needed.

Access

To do an "OR" search in the same field, enter Filter mode and place search terms in quotes and put "OR" in between them. To do an OR search query, make sure to include "OR" in the query design.
Note: Recent versions of Access also include an OR tab in the Filter form.

Google

Google and other online search engine support Boolean searches in the "Advanced Search" options.To do an "OR" search:

  1. Go to Google and click Advanced Search (right of search box).
  2. Enter keywords in the third box "with at least one of the words."

 

Exclusive OR (XOR)

Some database systems may recognize an "exclusive or (X OR)" operator. This differs from the normal OR operator in that the search looks for items which fulifill just one of the criteria but not both. To return to the "salsa" and "merengue" search, the statement salsa XOR merengue would exclude items which were both about salsa and merengue. If you were trying to isolate multiple criteria, you might want to use an exclusive or search. The XOR Venn diagram shows the two criteria circles again, but leaves the intersecting area white because those results are exculded.

X OR Diagram

Venn Diagram for XOR - Search Results are in green. Excluded results are in white.

Top of Page

The NOT Operator

The NOT operator is used to exclude items which meet a criteria (or find items which do not meet the given criteria). This operator is helpful for searches in which you want most records, but want to throw out a specific subset of them. This is also sometimes called an inverse search.

In the example below, the search is looking for items which are related to rap music for any language except English or NOT English. This is represented by a green circle containing rap music for all languages, with a white oval in the center for the English language records which have been excluded.

NOT Circle Diagram

Venn Diagram for NOT - Search Results are in green. Excluded results are in white.

 

The advantage to a NOT search is that sometimes it is easier to specify the criteria to be discarded rather than the criteria to be included. If you tried to specify that you wanted non-English rap music without the NOT operator, you would have to use a very long series of OR statements such as Spanish OR French OR Japanese OR Portuguese OR....

Note: A NOT search is also called an inverse search because you are inverting the search criteria.

File Maker Pro

For an "NOT" Find, do the following:

  1. Go into Find mode and enter the first search criteria into the form.
  2. Click the Omit box on the left side of the menu to exclude that criteria.

Access

To do an "NOT" search in the same field, enter Filter mode and place search terms in quotes and put "NOT" in front of it. To do an NOT search query, make sure to include "NOT" in the query design. You can also use "<>" as an alternative to NOT.

Google

Google and other online search engine support Boolean searches in the "Advanced Search" options.To do an "NOT" search:

  1. Go to Google and click Advanced Search (right of search box).
  2. Enter keywords in the fourth box "without the words."

Top of Page

Combining Boolean Operators

Many database applications allow you to use more than one Boolean operator within a single search string. If you have many keywords, you can include them all with multiple "AND" statements (e.g. Rap music AND Spanish AND Los Angeles for "Spanish rap music from Los Angeles"). Similarly, you can combine OR statements as in rumba OR salsa OR merengue.

One of the more interesting options is to combine a NOT operator with either the AND or the OR operator. For instances, if you wanted to find "non-English Los Angeles rap music", you could specify rap music AND Los Angeles AND NOT English.

FileMakerPro Tip: Use the Omit button and Add Request options to create complex searches. For the rap music AND Los Angeles AND NOT English search, you would do the following:

  1. Enter Find mode and enter "Los Angeles" and "rap music" into the appropriate fields.
  2. Go to Request then Add New Request.
  3. Enter "English" into the appropriate field, then click Omit.
  4. Click the Find button.

Access Tip: In theory, you can place som eBoolean statements in a parentheses such as in a statement Rap AND Spanish AND NOT (New York OR Los Angeles) for "Spanish rap outside New York or Los Angeles." However Access sometimes has difficulties evaluating Boolean statements in parentheses. You may have to re-write the logic to remove or readjust the parentheses. For instance: Rap And Spanish AND NOT New York AND NOT Los Angeles.

Google

Go to Google and click Advanced Search (right of search box) then enter. keywords in boxes for each of the search types.

Top of Page

Quick Review

Roll your mouse over the blue box after each question to see the answer.
Note: Answers are already displayed in older browsers.

How would you express these search problems in Boolean terms?

Only records about Monet and his use of color.
A: Monet AND color

Records about Central America or South America.
A: Central America OR South America

Students from all states except Pennsylvania.
A: NOT Pennsyvania

And these more complex searches?

Graduate students from all countiries except the United States.
A: Graduate AND Student AND NOT United States

Records about color for Monet and Manet.
A: There are at least two ways. Color AND (Monet OR Manet). If that did not work, then one could try (Manet AND Color) OR (Monet AND Color)

Next: Null Searches
Prev: Wildcard Searches

Top of Page

OTHER SECTIONS: Home Page | Site Map | Glossary | Teaching Ideas

© 2004-2005 The Pennsylvania State University.

This Website is maintained by Elizabeth Pyatt (ejp10@psu.edu) for Teaching and Learning with Technology, a unit of Information Technology Services.

Last Update: July 29, 2005