MySQL Database Quiz Questions

Course Name:MySQL
Chapter Name:Chapter 7 - DQL (Data Query Language)
Lesson Content Link:Sub Queries
Current Quiz Count:30
Progress
0%
Q1
True / False

A subquery in MySQL can be used in the WHERE clause to filter results.

Q2
True / False

Subqueries in MySQL must always be placed in parentheses.

Q3
True / False

A subquery can return multiple columns in MySQL.

Q4
True / False

A subquery in MySQL can be used in the SELECT clause to compute a value for each row.

Q5
True / False

Correlated subqueries in MySQL can reference columns from the outer query.

Q6
True / False

MySQL supports using subqueries in the HAVING clause.

Q7
True / False

In MySQL, a subquery in the FROM clause is known as a derived table or a common table expression (CTE).

Q8
True / False

You can use a subquery in MySQL to update multiple rows in the parent query.

Q9
True / False

Subqueries in MySQL are executed only once, regardless of the number of times they are referenced.

Q10
True / False

In MySQL, the EXISTS operator can be used in a subquery to test for the presence of rows that meet certain criteria.

Q11
Single Choice

Which of the following best describes a subquery in MySQL?

Q12
Single Choice

Which MySQL keyword is used to check if a subquery returns any rows?

Q13
Single Choice

What is the result of the following SQL query?

SQL Code
SELECT name FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
Q14
Single Choice

In MySQL, which of the following is true about correlated subqueries?

Q15
Single Choice

What will be the output of this SQL query?

SQL Code
SELECT department_id, (SELECT COUNT(*) FROM employees WHERE department_id = d.department_id) AS emp_count
FROM departments d;
Q16
Single Choice

What does this query return?

SQL Code
Consider the following SQL query:
SELECT product_id, product_name
FROM products
WHERE price = (SELECT MAX(price) FROM products);
Q17
Single Choice

Which of the following statements about using subqueries in MySQL is true?

Q18
Single Choice

What does this query do?

SQL Code
Analyze the following query:
SELECT order_id, order_date
FROM orders
WHERE customer_id IN (SELECT customer_id FROM customers WHERE country = 'USA')
AND order_date = (SELECT MAX(order_date) FROM orders WHERE customer_id = orders.customer_id);
Q19
Single Choice

What will be the output of the following query?

SQL Code
SELECT employee_id, salary
FROM employees e
WHERE salary > ALL (SELECT salary FROM employees WHERE department_id = e.department_id AND job_title = 'Manager');
Q20
Single Choice

What is the likely error or outcome?

SQL Code
Given the following SQL query:
SELECT employee_id, first_name, last_name
FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees GROUP BY department_id);
Q21
Multiple Choice

Which SQL query uses a subquery to find the names of employees who earn more than the average salary?

SQL Code
SELECT name FROM employees
WHERE salary > (SELECT AVG(salary) FROM employees);
Q22
Multiple Choice

Identify the SQL query that uses a subquery to find products that have been ordered more than 10 times.

SQL Code
SELECT product_name FROM products
WHERE product_id IN (SELECT product_id FROM orders GROUP BY product_id HAVING COUNT(*) > 10);
Q23
Multiple Choice

Which SQL query uses a subquery to list customers who have placed orders with a total value greater than $1000?

SQL Code
SELECT customer_name FROM customers
WHERE customer_id IN (SELECT customer_id FROM orders GROUP BY customer_id HAVING SUM(order_total) > 1000);
Q24
Multiple Choice

Determine the SQL query that uses a subquery to find all departments with an average employee salary above $50,000.

SQL Code
SELECT department_name FROM departments
WHERE department_id IN (SELECT department_id FROM employees GROUP BY department_id HAVING AVG(salary) > 50000);
Q25
Multiple Choice

Which SQL query uses a subquery to find the employees who have the highest salary in their department?

SQL Code
SELECT name FROM employees
WHERE salary = (SELECT MAX(salary) FROM employees e2 WHERE e2.department_id = employees.department_id);
Q26
Multiple Choice

Which SQL query uses a subquery to list products that have never been ordered?

SQL Code
SELECT product_name FROM products
WHERE product_id NOT IN (SELECT DISTINCT product_id FROM orders);
Q27
Multiple Choice

Identify the SQL query that uses a subquery to find all customers who have never placed an order.

SQL Code
SELECT customer_name FROM customers
WHERE customer_id NOT IN (SELECT DISTINCT customer_id FROM orders);
Q28
Multiple Choice

Which SQL query uses a subquery to find departments where the total salary exceeds $500,000?

SQL Code
SELECT department_name FROM departments
WHERE department_id IN (SELECT department_id FROM employees GROUP BY department_id HAVING SUM(salary) > 500000);
Q29
Multiple Choice

Determine the SQL query that uses a subquery to find the average salary of employees in each department.

SQL Code
SELECT department_name, AVG(salary) FROM employees
WHERE department_id IN (SELECT department_id FROM departments);
GROUP BY department_name;
Q30
Multiple Choice

Which SQL query uses a subquery to list the names of employees who work in the same department as 'John Doe'?

SQL Code
SELECT name FROM employees
WHERE department_id = (SELECT department_id FROM employees WHERE name = 'John Doe');