Complete the code to select all employees whose department ID is in the list returned by the subquery.
SELECT * FROM employees WHERE department_id [1] (SELECT id FROM departments WHERE location = 'New York');
The IN keyword is used to check if a value matches any value in a list returned by a subquery.
Complete the code to find products with prices greater than the average price returned by the subquery.
SELECT product_name FROM products WHERE price [1] (SELECT AVG(price) FROM products);The query selects products priced higher than the average price, so the comparison operator should be >.
Fix the error in the query to select customers who have placed orders with total amount greater than 1000.
SELECT customer_id FROM orders WHERE total_amount [1] (SELECT SUM(total_amount) FROM orders GROUP BY customer_id);The subquery returns multiple sums (one per customer), so to compare with any of these values, use ANY.
Fill both blanks to select employees whose salary is higher than the average salary in their department.
SELECT employee_id, salary FROM employees WHERE salary [1] (SELECT AVG(salary) FROM employees WHERE department_id [2] employees.department_id);
The query compares each employee's salary to the average salary in their own department. The first blank uses > to find higher salaries. The second blank uses = to match the department IDs.
Fill all three blanks to select products whose price is between the minimum and maximum prices in the same category.
SELECT product_name, price FROM products WHERE price [1] (SELECT MIN(price) FROM products WHERE category_id [2] products.category_id) AND price [3] (SELECT MAX(price) FROM products WHERE category_id = products.category_id);
The query finds products priced between the minimum and maximum in their category. The first blank uses >= to include prices equal or above the minimum. The second blank uses = to match category IDs. The third blank uses <= to include prices equal or below the maximum.