Bird
0
0

Why do we use subqueries in PostgreSQL?

easy📝 Conceptual Q11 of 15
PostgreSQL - Subqueries in PostgreSQL
Why do we use subqueries in PostgreSQL?
SELECT * FROM employees WHERE department_id IN (SELECT id FROM departments WHERE location = 'NY');
ATo change data types of columns
BTo speed up the database server automatically
CTo ask a question inside another query and filter results based on it
DTo create new tables from existing ones
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of the subquery

    The subquery (SELECT id FROM departments WHERE location = 'NY') finds department IDs located in NY.
  2. Step 2: See how the main query uses the subquery

    The main query selects employees whose department_id matches any ID from the subquery result.
  3. Final Answer:

    To ask a question inside another query and filter results based on it -> Option C
  4. Quick Check:

    Subqueries filter data using inner query results [OK]
Quick Trick: Subqueries answer inner questions to filter outer query [OK]
Common Mistakes:
  • Thinking subqueries speed up queries automatically
  • Confusing subqueries with table creation
  • Using subqueries to change data types

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes