Bird
0
0

Consider this SQL query:

medium📝 Debug Q14 of 15
SQL - Advanced Joins
Consider this SQL query:
SELECT * FROM A CROSS JOIN B WHERE A.id = B.id;
What is the main issue with this query?
AIt will cause a syntax error because CROSS JOIN cannot have WHERE clause.
BIt updates tables A and B unintentionally.
CIt returns no rows because CROSS JOIN filters all rows.
DIt produces the same result as INNER JOIN but less efficiently.
Step-by-Step Solution
Solution:
  1. Step 1: Understand CROSS JOIN with WHERE filter

    CROSS JOIN creates all pairs, then WHERE filters pairs where A.id = B.id.
  2. Step 2: Compare with INNER JOIN

    This is equivalent to INNER JOIN on A.id = B.id but less efficient because CROSS JOIN generates many unnecessary pairs first.
  3. Final Answer:

    It produces the same result as INNER JOIN but less efficiently. -> Option D
  4. Quick Check:

    CROSS JOIN + WHERE = INNER JOIN behavior [OK]
Quick Trick: CROSS JOIN + WHERE = INNER JOIN but slower [OK]
Common Mistakes:
MISTAKES
  • Thinking WHERE is invalid with CROSS JOIN
  • Assuming CROSS JOIN filters rows automatically
  • Confusing SELECT with UPDATE statements

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes