Bird
0
0

Which of the following is the correct way to use the EXISTS operator in an SQL query?

easy📝 Syntax Q3 of 15
SQL - Subqueries
Which of the following is the correct way to use the EXISTS operator in an SQL query?
ASELECT * FROM Employees e WHERE EXISTS (SELECT 1 FROM Departments d WHERE d.id = e.department_id);
BSELECT * FROM Employees e WHERE EXISTS SELECT 1 FROM Departments d WHERE d.id = e.department_id;
CSELECT * FROM Employees e WHERE EXISTS = (SELECT 1 FROM Departments d WHERE d.id = e.department_id);
DSELECT * FROM Employees e WHERE EXISTS IN (SELECT 1 FROM Departments d WHERE d.id = e.department_id);
Step-by-Step Solution
Solution:
  1. Step 1: Understand EXISTS syntax

    The EXISTS operator requires a subquery enclosed in parentheses.
  2. Step 2: Check each option

    SELECT * FROM Employees e WHERE EXISTS (SELECT 1 FROM Departments d WHERE d.id = e.department_id); correctly uses EXISTS with a subquery in parentheses.
    Options B, C, and D have syntax errors or incorrect usage.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    EXISTS must be followed by a subquery in parentheses [OK]
Quick Trick: EXISTS requires a subquery in parentheses [OK]
Common Mistakes:
MISTAKES
  • Omitting parentheses around the subquery
  • Using '=' or 'IN' with EXISTS
  • Incorrect placement of EXISTS keyword

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes