QueryCraft

Build a comparison value with a subquery

A subquery calculates a value inside another query. Computing a comparison value from current data, instead of hard-coding a number, keeps the condition meaningful as the data changes.

SELECT name FROM products WHERE price > (SELECT MIN(p.price) FROM products AS p WHERE p.stock > 0);

Common misunderstanding

A scalar subquery must return one column and at most one row. For a set of values, use an appropriate comparison such as IN.

Related missions

Practice opens in this page’s language. Change it in the practice options at any time.