0
0
SQLquery~20 mins

Three-valued logic (TRUE, FALSE, UNKNOWN) in SQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Three-Valued Logic Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Output of WHERE clause with NULL comparison
Consider a table employees with a column manager_id that can be NULL. What rows will be returned by this query?

SELECT * FROM employees WHERE manager_id = NULL;
SQL
CREATE TABLE employees (id INT, name VARCHAR(50), manager_id INT);
INSERT INTO employees VALUES (1, 'Alice', NULL), (2, 'Bob', 1), (3, 'Charlie', NULL);
ANo rows are returned because <code>manager_id = NULL</code> is UNKNOWN for all rows.
BAll rows where <code>manager_id</code> is NULL are returned.
CAll rows are returned regardless of <code>manager_id</code> value.
DThe query causes a syntax error due to NULL comparison.
Attempts:
2 left
💡 Hint
Remember that in SQL, = NULL does not behave like normal equality.
query_result
intermediate
2:00remaining
Effect of NOT on UNKNOWN in WHERE clause
Given a table products with a nullable column discount, what rows will this query return?

SELECT * FROM products WHERE NOT (discount > 10);
SQL
CREATE TABLE products (id INT, name VARCHAR(50), discount INT);
INSERT INTO products VALUES (1, 'Pen', 5), (2, 'Notebook', NULL), (3, 'Eraser', 15);
AOnly rows with discount > 10 are returned.
BOnly rows with discount <= 10 are returned; rows with NULL discount are excluded.
CRows with discount <= 10 and discount NULL are returned.
DNo rows are returned because NOT on UNKNOWN causes an error.
Attempts:
2 left
💡 Hint
Think about how NOT affects UNKNOWN in SQL's three-valued logic.
📝 Syntax
advanced
2:00remaining
Identify the error in three-valued logic expression
Which of the following WHERE clauses will cause a syntax error due to incorrect use of three-valued logic operators?
AWHERE (status = 'active' OR status IS NULL) AND NOT status = 'inactive'
BWHERE NOT (status = 'active' AND status IS NULL)
CWHERE status = 'active' AND NOT status IS NULL
DWHERE status = 'active' AND NOT (status IS NULL)
Attempts:
2 left
💡 Hint
Check operator precedence and how NOT applies to IS NULL.
optimization
advanced
2:00remaining
Optimizing queries with three-valued logic and NULLs
You want to select rows where score is either greater than 50 or unknown (NULL). Which query is more efficient and why?
ASELECT * FROM results WHERE NOT (score <= 50);
BSELECT * FROM results WHERE score > 50 OR score IS NULL;
CSELECT * FROM results WHERE score >= 51 OR score IS NULL;
DSELECT * FROM results WHERE COALESCE(score, 51) > 50;
Attempts:
2 left
💡 Hint
Consider how COALESCE affects NULL handling and index usage.
🧠 Conceptual
expert
2:00remaining
Understanding three-valued logic truth tables
Given the SQL three-valued logic, what is the result of this expression?

TRUE AND UNKNOWN OR NOT FALSE
ATRUE
BFALSE
CUNKNOWN
DSyntax error
Attempts:
2 left
💡 Hint
Evaluate step-by-step using SQL's three-valued logic truth tables.