0
0
SQLquery~5 mins

Nested subqueries in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a nested subquery in SQL?
A nested subquery is a query written inside another query. It helps to use the result of one query inside another query.
Click to reveal answer
beginner
Can a nested subquery return multiple rows?
Yes, a nested subquery can return multiple rows if used with operators like IN or EXISTS. But if used with =, it must return only one row.
Click to reveal answer
intermediate
How does a nested subquery help in filtering data?
A nested subquery can find a set of values or a single value that the outer query uses to filter its results, like finding employees who work in departments with more than 10 people.
Click to reveal answer
intermediate
What is the difference between a correlated and a non-correlated nested subquery?
A correlated subquery depends on the outer query for its values and runs once per row. A non-correlated subquery runs once and returns a result used by the outer query.
Click to reveal answer
beginner
Write a simple example of a nested subquery to find employees with salary above the average salary.
SELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
Click to reveal answer
What does a nested subquery do in SQL?
ACreates a new table
BRuns a query inside another query
CDeletes data from a table
DChanges the database schema
Which operator allows a nested subquery to return multiple rows?
AIN
B=
C<>
DBETWEEN
What is a correlated subquery?
AA subquery that deletes rows
BA subquery that runs once
CA subquery that creates a new table
DA subquery that depends on the outer query
Which of these is a valid use of a nested subquery?
AUPDATE employees SET salary = salary + 1000;
BDELETE FROM employees WHERE salary = 50000;
CSELECT * FROM employees WHERE salary > (SELECT AVG(salary) FROM employees);
DCREATE TABLE new_employees;
If a nested subquery returns more than one row but is used with '=', what happens?
AError occurs
BOnly first row is used
CQuery runs successfully
DRows are concatenated
Explain what a nested subquery is and give a simple example.
Think about a query inside another query.
You got /2 concepts.
    Describe the difference between correlated and non-correlated nested subqueries.
    Focus on how the subquery uses values from the outer query.
    You got /3 concepts.