Databases · Junior · Question 58 of 75

What is a subquery?

SELECT name FROM products
WHERE price > (SELECT AVG(price) FROM products);

Explanation

Subqueries can return one value (as here), a list for IN, or a whole table in FROM. CTEs (WITH) are often a more readable way to write them.

Further reading

Problem with a question

Databases · Junior · question 58

Test yourself

Take the Databases · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz