Bird
0
0

Why does the following PostgreSQL query cause an error?

medium📝 Debug Q7 of 15
PostgreSQL - Joins in PostgreSQL
Why does the following PostgreSQL query cause an error?
SELECT * FROM products CROSS JOIN sales ON products.id = sales.product_id;
ABecause CROSS JOIN does not support an ON clause for filtering.
BBecause the table names are incorrect.
CBecause the ON clause should use WHERE instead.
DBecause CROSS JOIN requires a USING clause instead of ON.
Step-by-Step Solution
Solution:
  1. Step 1: Understand CROSS JOIN limitations

    CROSS JOIN produces a Cartesian product and does not accept an ON clause for filtering.
  2. Step 2: Analyze the query

    The query incorrectly uses ON with CROSS JOIN, which is invalid syntax in PostgreSQL.
  3. Final Answer:

    Because CROSS JOIN does not support an ON clause for filtering. -> Option A
  4. Quick Check:

    ON clause is only valid with INNER or LEFT JOIN [OK]
Quick Trick: CROSS JOIN never uses ON clause [OK]
Common Mistakes:
  • Using ON clause with CROSS JOIN
  • Confusing CROSS JOIN with INNER JOIN
  • Trying to filter rows in CROSS JOIN directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes