0
0
MySQLquery~10 mins

AND, OR, NOT logical operators in MySQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to select rows where age is greater than 18 and status is 'active'.

MySQL
SELECT * FROM users WHERE age > 18 [1] status = 'active';
Drag options to blanks, or click blank then click option'
AXOR
BAND
CNOT
DOR
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR instead of AND selects rows that meet only one condition.
Using NOT here would negate a single condition, not combine two.
2fill in blank
medium

Complete the code to select rows where city is 'New York' or city is 'Los Angeles'.

MySQL
SELECT * FROM customers WHERE city = 'New York' [1] city = 'Los Angeles';
Drag options to blanks, or click blank then click option'
AXOR
BAND
COR
DNOT
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND would require the city to be both places at once, which is impossible.
Using NOT would negate a condition, not combine two.
3fill in blank
hard

Fix the error in the code to select rows where NOT status is 'inactive'.

MySQL
SELECT * FROM accounts WHERE [1] status = 'inactive';
Drag options to blanks, or click blank then click option'
ANOT
BAND
COR
DXOR
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND or OR here changes the logic and does not negate the condition.
XOR is not used for negation.
4fill in blank
hard

Fill both blanks to select rows where age is greater than 30 and city is not 'Chicago'.

MySQL
SELECT * FROM employees WHERE age > 30 [1] [2] city = 'Chicago';
Drag options to blanks, or click blank then click option'
AAND
BOR
CNOT
DXOR
Attempts:
3 left
💡 Hint
Common Mistakes
Using OR would select rows with age > 30 or city not Chicago, which is different logic.
Placing NOT after city without AND causes syntax errors.
5fill in blank
hard

Fill all three blanks to select rows where (salary > 50000 or position is 'Manager') and department is not 'Sales'.

MySQL
SELECT * FROM staff WHERE (salary > 50000 [1] position = 'Manager') [2] [3] department = 'Sales';
Drag options to blanks, or click blank then click option'
AAND
BOR
CNOT
DXOR
Attempts:
3 left
💡 Hint
Common Mistakes
Using AND inside parentheses changes the logic incorrectly.
Forgetting NOT before department causes wrong results.
Using XOR is not appropriate here.