In an SQL SELECT statement, a subquery is enclosed within which type of brackets or delimiters?

Difficulty: Easy

Correct Answer: ( )

Explanation:


Introduction / Context:
Subqueries are queries nested inside other SQL statements and are commonly used in WHERE, FROM, or SELECT clauses. Correct syntax is essential, and one of the most basic syntactic requirements is how to enclose a subquery. This question checks whether you remember the correct type of brackets used in standard SQL to surround a subquery.


Given Data / Assumptions:

  • We are using standard SQL syntax for subqueries.
  • A subquery is a complete SELECT statement nested within another statement.
  • The question asks which brackets or delimiters are used around the subquery.


Concept / Approach:
In SQL, subqueries are always enclosed in parentheses, which are round brackets written as ( and ). This is true whether the subquery appears in the WHERE clause, as in an IN or EXISTS predicate, or in the FROM clause as an inline view. Other bracket types such as square brackets, curly braces, or angle brackets have different uses or are not part of standard SQL syntax for subqueries.


Step-by-Step Solution:
Step 1: Recall a typical example: SELECT name FROM employees WHERE department_id IN (SELECT id FROM departments WHERE location = 'London'). Step 2: Observe that the inner SELECT statement is surrounded by ( and ), which are parentheses. Step 3: Note that [ ] are sometimes used in some systems to quote identifiers but not to define subqueries. Step 4: Note that { } and < > are not standard delimiters for SQL subqueries. Step 5: Conclude that ( ) is the correct choice for enclosing a subquery in a SELECT statement.


Verification / Alternative check:
You can open any SQL reference or tutorial and look at examples of subqueries. In all mainstream systems such as Oracle, MySQL, PostgreSQL, and SQL Server, subqueries are shown inside parentheses. Attempts to use other bracket types lead to syntax errors, confirming that parentheses are standard.


Why Other Options Are Wrong:
Option A, [ ], is incorrect because square brackets are used in some SQL dialects such as SQL Server to quote identifiers with special characters, for example [Order Details], not to delimit subqueries. Option B, { }, is incorrect because curly braces are not part of normal SQL subquery syntax and are sometimes used only in special extensions or drivers. Option C, < >, is incorrect because angle brackets are not used to mark subqueries and would cause syntax errors in standard SQL.


Common Pitfalls:
A common mistake is to confuse how different languages use brackets. For example, many programming languages use curly braces for code blocks, which can tempt beginners to use them in SQL. Another pitfall is misplacing parentheses so that the database engine does not recognize the intended subquery, leading to errors or unexpected behaviour. Always remember to surround the entire nested SELECT with a matching pair of parentheses in SQL.


Final Answer:
In SQL, a subquery in a SELECT statement is enclosed within ( ), that is, parentheses.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion