Q1
True / FalseIn MySQL, the logical operator AND returns true if both operands are true.
The AND operator returns true only if both conditions are true.
Q2
True / FalseThe OR logical operator in MySQL will return true if at least one of the operands is true.
The OR operator returns true if at least one of the conditions is true.
Q3
True / FalseIn MySQL, the NOT logical operator negates the value of the condition it precedes.
The NOT operator inverts the Boolean value of the condition it precedes.
Q4
True / FalseMySQL's logical operators AND and OR have the same precedence level.
In MySQL, the AND operator has a higher precedence than the OR operator.
Q5
True / FalseIn MySQL, the expression NULL AND TRUE will return NULL.
When using logical operators with NULL in MySQL, any expression involving NULL returns NULL.
Q6
True / FalseThe XOR operator in MySQL is used to return true if both operands are either true or both are false.
The XOR operator returns true if exactly one of the operands is true and the other is false.
Q7
True / FalseIn MySQL, the logical operator AND can be short-circuited.
In MySQL, AND short-circuits; if the first operand is false, the second operand is not evaluated.
Q8
True / FalseThe precedence of logical operators in MySQL is NOT, AND, then OR.
The logical operators in MySQL have the precedence order: NOT > AND > OR.
Q9
True / FalseIn MySQL, combining AND and OR in a single query without parentheses will always produce predictable results.
Without parentheses to explicitly define precedence, combining AND and OR can lead to ambiguous results.
Q10
True / FalseIn MySQL, using logical operators with subqueries in the WHERE clause can improve query performance.
Using logical operators with subqueries can sometimes slow down performance due to the complexity of subquery evaluation. It is often better to use joins when possible.
Q21
Multiple ChoiceWhich SQL query uses the AND operator to filter employees who work in department 5 and have a salary greater than 50,000?
SQL Code
SELECT name, department_id, salary
FROM employees
WHERE department_id = 5 AND salary > 50000;
The AND operator is used to filter rows where both conditions (department_id = 5 and salary > 50,000) must be true.
Q22
Multiple ChoiceIdentify the SQL query that uses the OR operator to find products that are either out of stock or priced above 100.
SQL Code
SELECT product_name, price, stock
FROM products
WHERE stock = 0 OR price > 100;
The OR operator is used to filter rows where at least one of the conditions (stock = 0 or price > 100) must be true.
Q24
Multiple ChoiceDetermine the SQL query that uses the AND and OR operators together to filter products that are in stock and either priced above 100 or belong to category 3.
SQL Code
SELECT product_name, price, stock
FROM products
WHERE stock > 0 AND (price > 100 OR category_id = 3);
The query combines AND and OR operators, where the AND condition ensures that products are in stock, and the OR condition allows either price or category condition to be true.
Q25
Multiple ChoiceWhich SQL query correctly uses the combination of AND and NOT operators to exclude employees with a salary below 50,000 and department 5?
SQL Code
SELECT name, department_id, salary
FROM employees
WHERE NOT (salary < 50000 AND department_id = 5);
The NOT operator negates the AND condition, excluding employees who meet both criteria (salary < 50,000 and department_id = 5).
Q26
Multiple ChoiceWhich SQL query uses the AND operator to select orders placed by customers from New York and with an order amount greater than 500?
SQL Code
SELECT order_id, customer_id, order_amount
FROM orders
WHERE customer_city = 'New York' AND order_amount > 500;
The AND operator is used to filter rows where both conditions (customer_city = 'New York' and order_amount > 500) must be true.
Q27
Multiple ChoiceIdentify the SQL query that uses the OR and NOT operators to find customers not from California or with an account balance above 1,000.
SQL Code
SELECT customer_name, state, account_balance
FROM customers
WHERE state != 'California' OR account_balance > 1000;
The OR operator is used to select rows where either condition (state not equal to California or account balance > 1000) is true.
Q28
Multiple ChoiceWhich SQL query demonstrates the correct use of AND, OR, and NOT operators together to filter a complex condition?
SQL Code
SELECT product_name, price, stock
FROM products
WHERE NOT (price < 50 OR stock = 0) AND category_id = 2;
The query correctly combines AND, OR, and NOT operators to filter rows where the price is not less than 50 or stock is not zero, and the category_id is 2.
Q29
Multiple ChoiceWhich SQL query correctly uses the combination of AND, OR, and NOT operators to exclude certain employees based on department and salary?
SQL Code
SELECT name, department_id, salary
FROM employees
WHERE department_id != 2 AND (salary > 60000 OR NOT department_id = 4);
The query excludes employees from department 2 and includes those with a salary > 60,000 or those not in department 4.
Q30
Multiple ChoiceWhich SQL query uses logical operators to find all orders placed by customers from either New York or California with an order amount greater than 500?
SQL Code
SELECT order_id, customer_id, order_amount
FROM orders
WHERE (customer_city = 'New York' OR customer_city = 'California') AND order_amount > 500;
The query combines OR and AND operators to filter orders where the customer is from either New York or California, and the order amount is greater than 500.