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- FALSE10 > 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 TRUEChallenge
EasyAvailable 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
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4More Keywords
The IN keywordThe BETWEEN keywordThe LIKE keywordThe AS keywordRecap - Cellphone Models2Conditions
Conditions BasicsThe AND keywordThe OR keywordThe NOT keywordMultiple Conditions CombinedParenthesisBooleans5Arithmetic Operations
Mathematical OperatorsMathematical ColumnsThe Modulo OperationThe ROUND() Function3Specific Return Format
Null valuesSort Results Part 1Sort Results Part 2Recap - Cyber Security FirmLimit number of recordsRecap - Vehicle Factory6Intro Challenges
Recap - Parliamentary ElectionRecap - Police Criminal ArrestRecap - Bar Beverage ContainerRecap - Engineer new columnsPractice on your own: SQL playground