0
0
MySQLquery~10 mins

Subqueries with IN operator 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 all employees who work in departments listed in the subquery.

MySQL
SELECT employee_name FROM employees WHERE department_id [1] (SELECT department_id FROM departments WHERE location = 'New York');
Drag options to blanks, or click blank then click option'
A=
BNOT IN
CIN
DLIKE
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of 'IN' when comparing to a subquery result.
Using 'LIKE' which is for pattern matching, not list membership.
2fill in blank
medium

Complete the code to find all products whose category_id is in the list of categories with more than 100 products.

MySQL
SELECT product_name FROM products WHERE category_id [1] (SELECT category_id FROM products GROUP BY category_id HAVING COUNT(*) > 100);
Drag options to blanks, or click blank then click option'
AIN
BNOT IN
C=
DBETWEEN
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which only compares to a single value, not a list.
Using 'BETWEEN' which is for ranges, not lists.
3fill in blank
hard

Fix the error in the query to select customers who have orders in the USA.

MySQL
SELECT customer_name FROM customers WHERE customer_id [1] (SELECT customer_id FROM orders WHERE country = 'USA');
Drag options to blanks, or click blank then click option'
AIN
BLIKE
CNOT IN
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' which causes an error if subquery returns multiple rows.
Using 'LIKE' which is for pattern matching, not list membership.
4fill in blank
hard

Fill both blanks to select orders where the product_id is in the list of products priced above 50.

MySQL
SELECT order_id FROM orders WHERE product_id [1] (SELECT product_id FROM products WHERE price [2] 50);
Drag options to blanks, or click blank then click option'
AIN
B>
C<
DNOT IN
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'NOT IN' instead of 'IN' for the first blank.
Using '<' instead of '>' for the price comparison.
5fill in blank
hard

Fill all three blanks to select employee names who work in departments located in 'London' and have a salary greater than 50000.

MySQL
SELECT employee_name FROM employees WHERE department_id [1] (SELECT department_id FROM departments WHERE location = [2]) AND salary [3] 50000;
Drag options to blanks, or click blank then click option'
AIN
B'London'
C>
DNOT IN
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'NOT IN' instead of 'IN' for the first blank.
Forgetting quotes around 'London' in the second blank.
Using '<' instead of '>' for the salary comparison.