Menu
Coddy logo textTech

Booleans

Part of the Fundamentals section of Coddy's SQL journey — lesson 11 of 72.

Conditions are booleans. Boolean is a data type with two possible values: TRUE or FALSE.

For example

  • 10 > 100 - FALSE
  • 10 > 5 - TRUE
  • 10 > 5 AND 100 < 5 - FALSE

Boolean columns have only two values - either TRUE or FALSE. Internally, TRUE is represented as 1 and FALSE is represented as 0. Each row in a boolean column holds one of these two values.

We can represent a status like employment as a single boolean column where 1 means employed and 0 means unemployed, making it easier to filter data. To filter data using booleans we will use the IS TRUE or IS NOT TRUE keywords.

SELECT *
FROM table1
WHERE col1 IS NOT FALSE AND col2 IS TRUE
challenge icon

Challenge

Easy

Available tables and columns:

  • <strong>objects</strong>: <strong>id</strong>, <strong>colorful</strong>

Fetch all of the colorful objects. Instead of writing colorful = 1 try to use the TRUE keyword.

Cheat sheet

Boolean is a data type with two possible values: TRUE or FALSE.

Examples:

  • 10 > 100 - FALSE
  • 10 > 5 - TRUE
  • 10 > 5 AND 100 < 5 - FALSE

Internally, TRUE is represented as 1 and FALSE is represented as 0.

To filter data using booleans, use IS TRUE or IS NOT TRUE keywords:

SELECT *
FROM table1
WHERE col1 IS NOT FALSE AND col2 IS TRUE

Try it yourself

quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals