0
0
SQLquery~5 mins

WHERE with NOT operator in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the NOT operator do in a SQL WHERE clause?
The NOT operator reverses the condition in the WHERE clause. It selects rows where the condition is false.
Click to reveal answer
beginner
Write a SQL query to select all employees who are NOT in the 'Sales' department.
SELECT * FROM employees WHERE NOT department = 'Sales';
Click to reveal answer
intermediate
Can the NOT operator be combined with other conditions in the WHERE clause?
Yes, NOT can be combined with AND, OR, and parentheses to create complex conditions.
Click to reveal answer
advanced
How does NOT work with NULL values in SQL WHERE clauses?
NOT with NULL returns UNKNOWN, so rows with NULL in the condition are not selected unless IS NULL or IS NOT NULL is used.
Click to reveal answer
intermediate
Rewrite this query using NOT: SELECT * FROM products WHERE category <> 'Books';
SELECT * FROM products WHERE NOT category = 'Books';
Click to reveal answer
What does this query return? SELECT * FROM users WHERE NOT active = 1;
AUsers who are not active
BUsers who are active
CAll users
DNo users
Which is equivalent to: WHERE NOT (age > 30)?
AWHERE age <= 30
BWHERE age = 30
CWHERE age < 30
DWHERE age > 30
What happens if you use NOT with a NULL value in a condition?
AReturns TRUE
BReturns UNKNOWN (no rows selected)
CReturns FALSE
DReturns an error
How to select rows where status is NOT 'completed' or 'pending'?
AWHERE NOT status = 'completed' OR status = 'pending'
BWHERE status != 'completed' AND status != 'pending'
CWHERE NOT (status = 'completed' OR status = 'pending')
DWHERE status = 'completed' AND status = 'pending'
Which query uses NOT correctly to exclude 'admin' users?
ASELECT * FROM users WHERE NOT role = 'admin'
BSELECT * FROM users WHERE role != 'admin'
CSELECT * FROM users WHERE NOT role != 'admin'
DSELECT * FROM users WHERE role = 'admin'
Explain how the NOT operator changes the meaning of a condition in a SQL WHERE clause.
Think about what happens when you say NOT true or NOT false.
You got /3 concepts.
    Describe how to combine NOT with other conditions to filter data in SQL.
    Consider how NOT affects multiple conditions together.
    You got /4 concepts.