Subqueries: a question inside a question
A subquery nests one SELECT inside another. A scalar subquery returns one value, such as the average salary. IN can compare against multiple returned rows. Keep the expected shape clear.
हिन्दी में समझें
सबक्वेरी एक SELECT के अंदर दूसरा सवाल है। स्केलर सबक्वेरी एक मान देती है, जैसे औसत वेतन। IN कई परिणामों से तुलना कर सकता है।
अभ्यास: औसत उत्पाद मूल्य से महँगे उत्पाद का name और price, id क्रम।
Hinglish mein samjhein
Subquery ek SELECT ke andar doosra SELECT hai. Scalar subquery ek value deta hai, average salary jaisi. IN multiple returned rows se compare kar sakta hai.
Practice: Average product price se mehange product name,price id sorted.
A small SQL example
SELECT name,salary FROM employees WHERE salary > (SELECT AVG(salary) FROM employees) ORDER BY id;Examples use the fictional shop database bundled with the SQL playground: customers, products, orders, order_items and employees. The engine is SQLite; other SQL dialects may differ.
Try this example in the SQL playground →Practise this idea
Show product name and price above the average product price, ordered by id.
Check answer & explanation
SELECT name,price FROM products WHERE price > (SELECT AVG(price) FROM products) ORDER BY id;The scalar subquery calculates one overall average price. The outer WHERE compares each product price to that value.
Stuck in the course? Choose Check answer for either the challenge or quiz. Read the explanation and continue to the next lesson at your own pace.
Check your understanding
A scalar subquery returns…
Check the quiz answer
One value
A subquery nests one SELECT inside another. A scalar subquery returns one value, such as the average salary. IN can compare against multiple returned rows. Keep the expected shape clear.
References & corrections
Use the official SQLite documentation for full language rules. Read how these lessons are made and checked. Found a mistake? Report it to Excel Keys with this lesson URL and a reproducible example.