Bird
0
0

Identify the error in the following SQL query joining three tables:

medium📝 Debug Q6 of 15
SQL - Advanced Joins
Identify the error in the following SQL query joining three tables:
SELECT P.name, Q.description, R.cost FROM P JOIN Q ON P.id = Q.p_id JOIN R ON Q.id = R.q_id WHERE R.cost > 100;
AThe JOIN condition between Q and R is incorrect; it should be P.id = R.p_id.
BThere is no error; the query is syntactically correct.
CThe SELECT clause references columns not present in the tables.
DThe WHERE clause should be placed before the JOIN statements.
Step-by-Step Solution
Solution:
  1. Step 1: Review JOIN conditions

    The query joins P to Q on P.id = Q.p_id and Q to R on Q.id = R.q_id, which is consistent.
  2. Step 2: Check SELECT and WHERE clauses

    All selected columns exist in their respective tables, and the WHERE clause is correctly placed after JOINs.
  3. Final Answer:

    There is no error; the query is syntactically correct. - The query is syntactically correct.
  4. Quick Check:

    Verify join keys and clause order [OK]
Quick Trick: Check join keys and clause order carefully [OK]
Common Mistakes:
MISTAKES
  • Misplacing WHERE clause before JOINs
  • Incorrect join conditions
  • Selecting columns not in tables

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes