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- FALSE10 > 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 TRUEChallenge
EasyAvailable 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- FALSE10 > 5- TRUE10 > 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 TRUETry 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 columns