Bird
0
0

Find the error in this SQL query:

medium📝 Debug Q6 of 15
SQL - Subqueries
Find the error in this SQL query:
SELECT emp_name FROM Employees WHERE dept_id = (SELECT dept_id FROM Departments WHERE dept_name = 'Finance' OR);
AThe subquery has a trailing OR without a condition.
BThe main query is missing a GROUP BY clause.
CThe subquery should use IN instead of =.
DThe table alias is missing in the subquery.
Step-by-Step Solution
Solution:
  1. Step 1: Review the subquery syntax

    The subquery ends with 'OR' but lacks a condition after it, causing a syntax error.
  2. Step 2: Check other options

    GROUP BY is not required here; '=' is valid if subquery returns one value; aliasing is optional.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Trailing logical operators need conditions [OK]
Quick Trick: Logical operators must have conditions on both sides [OK]
Common Mistakes:
MISTAKES
  • Leaving dangling AND/OR without conditions
  • Confusing '=' with IN for subqueries
  • Assuming alias is mandatory in subqueries

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes