Bird
0
0

Which of the following demonstrates a valid subquery syntax in PostgreSQL?

easy📝 Syntax Q3 of 15
PostgreSQL - Subqueries in PostgreSQL
Which of the following demonstrates a valid subquery syntax in PostgreSQL?
ASELECT name FROM employees WHERE department_id = (SELECT id FROM departments WHERE name = 'HR');
BSELECT name FROM employees WHERE department_id = SELECT id FROM departments WHERE name = 'HR';
CSELECT name FROM employees WHERE department_id IN SELECT id FROM departments WHERE name = 'HR';
DSELECT name FROM employees WHERE department_id = {SELECT id FROM departments WHERE name = 'HR'};
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct subquery syntax

    Subqueries must be enclosed in parentheses.
  2. Step 2: Evaluate options

    SELECT name FROM employees WHERE department_id = (SELECT id FROM departments WHERE name = 'HR'); correctly uses parentheses around the subquery.
  3. Final Answer:

    SELECT name FROM employees WHERE department_id = (SELECT id FROM departments WHERE name = 'HR'); -> Option A
  4. Quick Check:

    Subqueries require parentheses [OK]
Quick Trick: Subqueries always need parentheses [OK]
Common Mistakes:
  • Omitting parentheses around subqueries
  • Using incorrect brackets or syntax
  • Placing subquery outside WHERE clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes