0
0
MySQLquery~10 mins

Scalar subqueries 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 the name and the highest salary from the employees table using a scalar subquery.

MySQL
SELECT name, (SELECT [1] FROM employees) AS max_salary FROM employees;
Drag options to blanks, or click blank then click option'
ACOUNT(salary)
BMAX(salary)
Csalary
DMIN(salary)
Attempts:
3 left
💡 Hint
Common Mistakes
Using salary without aggregation returns multiple rows causing an error.
Using COUNT(salary) returns the number of salaries, not the highest salary.
2fill in blank
medium

Complete the code to find employees whose salary is equal to the average salary using a scalar subquery.

MySQL
SELECT name FROM employees WHERE salary = (SELECT [1] FROM employees);
Drag options to blanks, or click blank then click option'
AAVG(salary)
BMIN(salary)
CSUM(salary)
DMAX(salary)
Attempts:
3 left
💡 Hint
Common Mistakes
Using MAX(salary) or MIN(salary) returns wrong comparison values.
Using SUM(salary) returns the total salary, not average.
3fill in blank
hard

Fix the error in the scalar subquery to correctly find employees with salary greater than the average salary.

MySQL
SELECT name FROM employees WHERE salary > (SELECT [1]salary FROM employees);
Drag options to blanks, or click blank then click option'
AMAX(
BFROM
CAVG(
DMIN(
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting AVG() parentheses causes syntax errors.
Using FROM without an aggregate function is invalid here.
4fill in blank
hard

Fill both blanks to select employees whose salary is between the minimum and maximum salary using scalar subqueries.

MySQL
SELECT name FROM employees WHERE salary BETWEEN (SELECT [1](salary) FROM employees) AND (SELECT [2](salary) FROM employees);
Drag options to blanks, or click blank then click option'
AMIN
BMAX
CAVG
DCOUNT
Attempts:
3 left
💡 Hint
Common Mistakes
Using AVG() or COUNT() returns incorrect ranges.
Swapping MIN and MAX changes the logic.
5fill in blank
hard

Fill all three blanks to select employees whose salary is greater than the average salary but less than the maximum salary.

MySQL
SELECT name FROM employees WHERE salary > (SELECT [1](salary) FROM employees) AND salary < (SELECT [2](salary) FROM employees) ORDER BY [3];
Drag options to blanks, or click blank then click option'
AMIN
BAVG
Csalary
DMAX
Attempts:
3 left
💡 Hint
Common Mistakes
Using MIN() instead of AVG() or MAX() causes wrong filtering.
Ordering by an aggregate function instead of a column causes errors.