0
0
SQLquery~10 mins

Subquery with IN operator in SQL - 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.

SQL
SELECT * 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'
ALIKE
B=
CIN
DNOT
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of 'IN' causes an error because '=' expects a single value, not a list.
Using 'LIKE' is for pattern matching, not for checking membership in a list.
2fill in blank
medium

Complete the code to find all products whose category_id is in the list of categories with 'Electronics' in their name.

SQL
SELECT product_name FROM products WHERE category_id [1] (SELECT category_id FROM categories WHERE category_name LIKE '%Electronics%');
Drag options to blanks, or click blank then click option'
A=
BBETWEEN
CNOT IN
DIN
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' will cause an error because the subquery returns multiple rows.
Using 'BETWEEN' is for ranges, not for lists of values.
3fill in blank
hard

Fix the error in the query to select customers who have orders in the 'Pending' status.

SQL
SELECT customer_name FROM customers WHERE customer_id [1] (SELECT customer_id FROM orders WHERE status = 'Pending');
Drag options to blanks, or click blank then click option'
ANOT IN
BIN
CLIKE
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' causes an error when the subquery returns more than one row.
Using 'LIKE' is incorrect because it is for pattern matching strings.
4fill in blank
hard

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

SQL
SELECT order_id, product_id FROM orders WHERE product_id [1] (SELECT product_id FROM products WHERE price [2] 100);
Drag options to blanks, or click blank then click option'
AIN
B>
C<
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of 'IN' for the first blank causes errors.
Using '<' instead of '>' in the second blank selects cheaper products, not expensive ones.
5fill in blank
hard

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

SQL
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'Chicago'
C>
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting quotes around 'Chicago' causes syntax errors.
Using '=' instead of '>' for salary filters out employees with higher salaries.