Menu
CoddyTech

Booleans

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

Conditions are booleans. A boolean value is either TRUE or FALSE. A comparison with an unknown value, as in NULL > 5, evaluates to NULL instead.

For example

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

SQLite has no separate boolean type. Internally, TRUE is represented as 1 and FALSE is represented as 0, and a boolean column is a column meant to hold 1 or 0 in each row. SQLite does not enforce this, so the column can also hold NULL or any other value.

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:

  • objects: id, colorful

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

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

Practice on your own: SQL playground