Challenge - 5 Problems
Boolean Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Boolean comparison in WHERE clause
Given the table users with a boolean column
is_active, what rows will be returned by this query?SELECT * FROM users WHERE is_active = TRUE;
PostgreSQL
CREATE TABLE users (id SERIAL PRIMARY KEY, name TEXT, is_active BOOLEAN); INSERT INTO users (name, is_active) VALUES ('Alice', TRUE), ('Bob', FALSE), ('Carol', NULL);
Attempts:
2 left
💡 Hint
Remember that in SQL, NULL means unknown and does not equal TRUE or FALSE.
✗ Incorrect
The condition 'is_active = TRUE' filters only rows where is_active is TRUE. Rows with FALSE or NULL do not satisfy this condition.
❓ query_result
intermediate1:30remaining
Boolean logic with NULL values
What is the result of this query?
SELECT TRUE AND NULL AS result;
Attempts:
2 left
💡 Hint
Think about how SQL treats unknown values in boolean logic.
✗ Incorrect
In SQL, TRUE AND NULL results in NULL because NULL represents unknown, so the result is unknown.
📝 Syntax
advanced1:30remaining
Correct boolean literal usage in PostgreSQL
Which option uses the correct boolean literal in PostgreSQL to insert a TRUE value?
Attempts:
2 left
💡 Hint
PostgreSQL accepts boolean literals TRUE and FALSE without quotes.
✗ Incorrect
PostgreSQL boolean literals are TRUE and FALSE without quotes. Using strings or numbers may cause errors or implicit casts.
❓ query_result
advanced1:30remaining
Boolean expression evaluation in SELECT
What is the output of this query?
SELECT CASE WHEN FALSE OR NULL THEN 'Yes' ELSE 'No' END AS answer;
Attempts:
2 left
💡 Hint
Remember how OR works with NULL in SQL's three-valued logic.
✗ Incorrect
FALSE OR NULL evaluates to NULL (unknown), so the CASE condition is false, returning 'No'.
🧠 Conceptual
expert2:30remaining
Behavior of boolean aggregates with NULLs
Consider a table
checks with a boolean column passed containing TRUE, FALSE, and NULL values. What does the aggregate function bool_and(passed) return if any row has FALSE, but some rows have NULL?Attempts:
2 left
💡 Hint
bool_and returns TRUE only if all non-null inputs are TRUE.
✗ Incorrect
bool_and returns FALSE if any input is FALSE, ignoring NULLs. So presence of FALSE causes FALSE result.