0
0
MySQLquery~5 mins

AND, OR, NOT logical operators in MySQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the AND operator do in a SQL WHERE clause?
The AND operator combines two conditions and returns true only if both conditions are true.
Click to reveal answer
beginner
How does the OR operator work in SQL?
The OR operator returns true if at least one of the combined conditions is true.
Click to reveal answer
beginner
Explain the NOT operator in SQL.
The NOT operator reverses the result of a condition. If the condition is true, NOT makes it false, and vice versa.
Click to reveal answer
intermediate
Write a SQL query using AND and OR to find employees who are in department 10 and have a salary over 5000 or are in department 20.
SELECT * FROM employees WHERE (department_id = 10 AND salary > 5000) OR department_id = 20;
Click to reveal answer
intermediate
Why is it important to use parentheses when combining AND and OR in SQL?
Parentheses control the order of evaluation, ensuring the query logic works as intended by grouping conditions properly.
Click to reveal answer
Which SQL operator returns true only if both conditions are true?
AAND
BOR
CNOT
DBETWEEN
What does the OR operator do in SQL?
AChecks for equality
BReturns true if both conditions are false
CNegates a condition
DReturns true if at least one condition is true
How does the NOT operator affect a condition?
AIt makes the condition always true
BIt combines two conditions
CIt reverses the condition's result
DIt checks if a value is null
Which query correctly finds rows where age is over 30 AND city is 'New York'?
ASELECT * FROM table WHERE age > 30 AND city = 'New York';
BSELECT * FROM table WHERE age > 30 OR city = 'New York';
CSELECT * FROM table WHERE NOT age > 30 AND city = 'New York';
DSELECT * FROM table WHERE age > 30 NOT city = 'New York';
Why use parentheses in a WHERE clause with AND and OR?
ATo make the query run faster
BTo group conditions and control evaluation order
CTo comment out parts of the query
DTo format the query for readability only
Describe how AND, OR, and NOT logical operators work in SQL WHERE clauses.
Think about how these operators combine or change conditions.
You got /3 concepts.
    Explain why parentheses are important when using AND and OR together in SQL queries.
    Consider how math uses parentheses to clarify operations.
    You got /3 concepts.