Challenge - 5 Problems
NOT Operator Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
Output of NOT operator in WHERE clause
Given a table Employees with columns
id, name, and department, what is the output of the following query?SELECT name FROM Employees WHERE NOT department = 'Sales';
SQL
CREATE TABLE Employees (id INT, name VARCHAR(50), department VARCHAR(50)); INSERT INTO Employees VALUES (1, 'Alice', 'Sales'), (2, 'Bob', 'HR'), (3, 'Charlie', 'Sales'), (4, 'Diana', 'IT');
Attempts:
2 left
💡 Hint
The NOT operator reverses the condition inside the WHERE clause.
✗ Incorrect
The query selects employees whose department is NOT 'Sales'. Bob and Diana belong to 'HR' and 'IT' respectively, so they are returned.
🧠 Conceptual
intermediate2:00remaining
Understanding NOT with multiple conditions
Consider the query:
Which rows will this query return?
SELECT * FROM Products WHERE NOT (category = 'Electronics' OR price > 1000);
Which rows will this query return?
Attempts:
2 left
💡 Hint
NOT reverses the entire condition inside the parentheses.
✗ Incorrect
The condition inside parentheses is true if category is 'Electronics' or price is greater than 1000. NOT reverses this, so only rows where both are false are returned.
📝 Syntax
advanced2:00remaining
Identify the syntax error with NOT operator
Which of the following SQL queries will cause a syntax error?
Attempts:
2 left
💡 Hint
Look for incomplete conditions inside parentheses.
✗ Incorrect
Option A has an incomplete condition inside the parentheses after AND, causing a syntax error.
❓ optimization
advanced2:00remaining
Optimizing NOT conditions in WHERE clause
Which query is more efficient for filtering rows where
status is not 'Active'?Attempts:
2 left
💡 Hint
Consider how the database engine optimizes comparison operators.
✗ Incorrect
Using the inequality operator (<>) is generally more efficient and clearer than using NOT with equality.
🔧 Debug
expert3:00remaining
Debugging unexpected results with NOT operator
A developer wrote this query:
They expected to get customers who are not from New York and are from the USA. Why does this query return more rows than expected?
SELECT * FROM Customers WHERE NOT city = 'New York' OR country = 'USA';
They expected to get customers who are not from New York and are from the USA. Why does this query return more rows than expected?
Attempts:
2 left
💡 Hint
Think about operator precedence and how NOT and OR combine.
✗ Incorrect
NOT has higher precedence than OR, so the condition is evaluated as (NOT city = 'New York') OR country = 'USA'. This returns rows where city is not New York or country is USA, which is more than expected.