Bird
0
0

Why do we use subqueries in SQL?

easy📝 Conceptual Q11 of 15
SQL - Subqueries
Why do we use subqueries in SQL?
SELECT * FROM employees WHERE department_id IN (SELECT id FROM departments WHERE location = 'NY');
ATo use the result of one query inside another for filtering or comparison
BTo speed up the database server automatically
CTo create new tables from existing ones
DTo change the database schema
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of subqueries

    The subquery inside the IN clause fetches department IDs located in 'NY'.
  2. Step 2: See how the main query uses subquery results

    The main query selects employees whose department_id matches those IDs from the subquery.
  3. Final Answer:

    To use the result of one query inside another for filtering or comparison -> Option A
  4. Quick Check:

    Subqueries help filter data using other query results [OK]
Quick Trick: Subqueries let queries talk to each other inside SQL [OK]
Common Mistakes:
MISTAKES
  • Thinking subqueries speed up queries automatically
  • Confusing subqueries with table creation
  • Believing subqueries change database structure

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes