Boolean logic

Boolean logic is a fundamental concept in computer science and mathematics that deals with true or false values. It provides a structured way to process information and make decisions in computing systems. Boolean logic is widely used in programming, databases, and search algorithms to filter, sort, and manipulate data efficiently. By applying Boolean operators, we can create precise conditions that guide decision-making in automated systems, ensuring accuracy and efficiency.

The three primary Boolean operators are:

  • AND: Both conditions must be TRUE for the result to be TRUE.
  • OR: At least one condition must be TRUE for the result to be TRUE.
  • NOT: Reverses the truth value, making TRUE become FALSE and vice versa.

Watch this short (2-min) video on Boolean logic. 

Video summary
  • The video explains how to create Boolean truth tables.
  • For a single variable, such as B, list all possible Boolean values: false and true.
  • For NOT B, the result is the opposite of B: false becomes true, and true becomes false.
  • For expressions with two variables, such as A AND B, create one column for each variable and list every possible combination.
  • Two variables produce four combinations, calculated as 22: 00, 01, 10, and 11.
  • For an AND expression, the result is only true when all inputs are true.
  • For expressions with three variables, such as A AND B AND C, there are eight combinations, calculated as 23.
  • A systematic binary counting approach helps avoid missing or duplicating combinations in the truth table.
  • The general method is: create one column per variable, calculate the number of combinations using 2n, list the binary combinations, then evaluate the expression.
  • For more complex expressions, start by evaluating anything inside brackets.
  • After brackets, work through the rest of the expression from left to right when operators have the same priority.
  • For OR expressions, the result is true when at least one of the values being compared is true.
  • The video ends by reinforcing that these steps provide a basic process for setting up truth tables before moving on to more complex expressions.

Did you know that Boolean logic is named after George Boole, a 19th-century mathematician and logician who developed the system of logical operations that formed the foundation of modern computing and database queries?

Thinking like a chess club president

Imagine you're organising a school chess club for students in Years 7–12. You need to determine who meets specific criteria to participate in a tournament at VSV. You have access to a membership database. What Boolean query would you use to filter the data accurately?

1️⃣ Who is in Year 10 AND has won a tournament?

  • Both conditions must be TRUE → AND

2️⃣ Who is in Year 7 OR Year 8?

  • At least one condition must be TRUE → OR

3️⃣ Who is NOT in Year 12?

  • This condition must be FALSE → NOT

How Boolean works in action

This table illustrates how we can structure these this query using Boolean logic.

Operator Meaning Example
AND Both must be TRUE 'Find students in Year 10 AND tournament winners.'
OR At least one must be TRUE 'Find students in Year 7 OR Year 8.'
NOT Must be FALSE 'Find students who are NOT in Year 12.'


How Boolean works in SQL

When using SQL, Boolean logic is applied in the WHERE clause:

SELECT * FROM chess_club
WHERE year_level = 10
AND tournament_winner = True;

Sharing a real-world example

Have you ever struggled to find exactly what you're looking for on Google? Boolean logic helps you refine your Google search results! Try some of these out.

For example:

  • AND: chess AND strategy
    find pages that include both terms.
  • OR: chess OR checkers
    find pages that mention either game.
  • NOT: chess -online
    exclude results related to online chess.

Using Boolean logic in search queries allows you to narrow down results and find what you need more efficiently.

Why learn Boolean logic

Boolean logic is used by us in many areas of computing, including:

  • Databases: Filtering and searching for specific records.
  • Programming: Making decisions based on conditions.
  • Artificial Intelligence: Helping AI systems evaluate multiple scenarios.
  • Web search engines: Refining search queries to get the most relevant results.
  • Library catalogues: Searching for books or resources by combining keywords.

Mastering Boolean logic gives you better control over how data is processed, filtered, and used to make informed decisions. In our course, we will apply this in SQL to examine and clean data and in spreadsheets for conditional formatting and formulas. This aligns with Unit 3 Outcome 1 of the study design, which focuses on data manipulation and validation techniques.

Link to the Study Design

Unit 3, Outcome 1: Where students learn data manipulation and SQL querying techniques. Boolean logic underpins:

  • Data querying and filtering: Using Boolean operators (AND, OR, NOT) in SQL to refine search results and manage large datasets effectively.
  • Data validation and decision-making: Ensuring logical accuracy in data-driven problem-solving.
  • Computational thinking and problem-solving: Developing structured approaches to analysing and organising data.