Boolean

Table of contents

Summarise with:

The Boolean operators or search operators are words or symbols used in programming to combine or modify logical conditions, They are present in almost all the countries where the programming languages. They are named after George Boole, a 19th century British mathematician who developed Boolean algebra, a branch of mathematics that deals with truth values and logical operations.

Main types of Boolean operators

There are three elementary types of Boolean operators: AND, OR and NOT. All three are very easy to understand, since they perfectly mimic the human soul and represent a programming logic elementary. We explain this triad in detail:

AND

This operator combines two conditions and returns true if both conditions are true. Thus, AND narrows the search range by telling the database that it wants to find items that meet a concatenation of specific characteristics.

Example: Suppose we want to search for documents containing the words cats and dogs. We would use a boolean query like cats AND dogs. This ensures that only results that contain both words are returned.

OR

The operator combines two conditions and returns true if at least one of the conditions is true. Conversely, the OR operator broadens the search range by telling the database that a number of terms are equally valid to display broader search results.

Example: If we want to search for documents containing the word cats or the word dogs, we would use a boolean query such as cats OR dogs. This would return results that contain at least one of these words.

NOT

The NOT operator negates a condition and returns true if the condition is false and, conversely, returns false if the condition is true. NOT narrows the search range in the opposite way to AND: by discarding search results based on exclusive characteristics.

Example: If we want to search for documents that contain the word cats but not the word dogs, we would use a boolean query such as cats NOT dogs. This ensures that results are returned that contain cats, but exclude those that also contain dogs.

Other types of Boolean operators

In addition to the basic Boolean operators (AND, OR, NOT), there are other less frequent operators that can be used to manipulate and compare Boolean values in different contexts.

XOR

The XOR operator returns true when exactly one of the two conditions is true, but not both. If both conditions are true or both are false, it returns false.

That is, it returns:

  • True if one condition is true and the other is false.
  • False if both conditions are true or both are false.

ExampleIf you want to find articles that mention either dogs or cats, but not both at the same time, you would use XOR. This will give you results that contain only dogs or only cats, but not those that mention both.

NAND

The NAND operator returns true when at least one of the conditions is false. It returns false only when both conditions are true. It is the result of applying a negation to the AND operator.

That is, it returns:

  • True if at least one condition is false.
  • False if both conditions are true.

ExampleIf you want to search for articles that do not mention both dogs and cats together, you would use NAND. This will return results that mention only dogs, only cats or neither, but not those that mention both.

NOR

The NOR operator returns true only when both conditions are false. If at least one of the conditions is true, it returns false. This is the result of applying a negation to the OR operator.

ExampleIf you are looking for articles that do not mention dogs or cats, you would use NOR. This will filter out all articles that mention at least one of these animals and only show you those that don't mention them at all.

==

This operator compares two values and returns true if both are equal. If the values are different, it returns false.

ExampleIf you want to check if an article contains exactly the word dogs, you would use the equality operator. This is useful for finding articles where the mention of dogs exactly matches the search term.

!=

This operator compares two values and returns true if they are different. If the values are the same, it returns false.

ExampleIf you want to search for articles that mention any animal except cats, you would use the inequality operator. This will allow you to find texts that talk about other animals, but specifically exclude cats.

Share in:

Related articles

Blockchain

The blockchain, also known as blockchain, is an information storage technology that is used to maintain a decentralised and secure record of information in an interlocking fashion. Let's say that the blockchain is a giant interconnected database that records

Batch process

Batch processing, also known as batch processing or batch processing, is a methodology used in computing to execute a series of tasks or programmes automatically, without user intervention. This type of processing groups multiple tasks

ETL

An ETL (Extract, Transform, Load) process is a technique used to integrate data from different sources and transform them into a common format for analysis and use in business information systems. The purpose of ETL processes is to achieve a

Pipeline

In computing, a pipeline, also known as a data pipeline, is a series of data processing elements connected in series, where the output of one element is the input of the next. The elements of a pipeline execute at

Scroll to Top