SQL - SubqueriesWhy might a database optimizer choose to rewrite a subquery as a JOIN internally?ABecause JOINs can be optimized with indexes and reduce repeated scanning.BBecause subqueries are always slower and not supported in modern SQL.CBecause JOINs use less memory than subqueries in all cases.DBecause subqueries cannot filter rows effectively.Check Answer
Step-by-Step SolutionSolution:Step 1: Understand optimizer behaviorDatabase optimizers rewrite queries to improve performance by using the best execution plan.Step 2: Reason why JOIN rewrite helpsJOINs can use indexes and avoid scanning subqueries repeatedly, improving speed.Final Answer:Because JOINs can be optimized with indexes and reduce repeated scanning. -> Option AQuick Check:Optimizer rewrites = better JOIN plans [OK]Quick Trick: Optimizers rewrite subqueries to JOINs for speed [OK]Common Mistakes:MISTAKESThinking subqueries are unsupportedAssuming JOINs always use less memoryBelieving subqueries cannot filter rows
Master "Subqueries" in SQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More SQL Quizzes Advanced Joins - Joining more than two tables - Quiz 3easy Advanced Joins - Join order and performance impact - Quiz 1easy Advanced Joins - FULL OUTER JOIN behavior - Quiz 5medium GROUP BY and HAVING - How GROUP BY changes query execution - Quiz 3easy GROUP BY and HAVING - WHERE vs HAVING mental model - Quiz 2easy Subqueries - Correlated subquery execution model - Quiz 9hard Table Constraints - CHECK constraint - Quiz 6medium Table Relationships - ER diagram to table mapping - Quiz 3easy Table Relationships - Many-to-many with junction tables - Quiz 6medium Views - CREATE VIEW syntax - Quiz 7medium