Which of the following is the correct syntax for using a scalar subquery in the SELECT clause?
easy📝 Syntax Q12 of 15
SQL - Subqueries
Which of the following is the correct syntax for using a scalar subquery in the SELECT clause?
ASELECT name, SELECT MAX(score) FROM scores AS max_score FROM students;
BSELECT name, (SELECT MAX(score) FROM scores) AS max_score FROM students;
CSELECT name, MAX(score) FROM scores AS max_score FROM students;
DSELECT name, (MAX(score) FROM scores) AS max_score FROM students;
Step-by-Step Solution
Solution:
Step 1: Identify correct scalar subquery syntax
The scalar subquery must be enclosed in parentheses and used inside the SELECT clause.
Step 2: Check each option
SELECT name, (SELECT MAX(score) FROM scores) AS max_score FROM students; correctly uses parentheses around the subquery. Others miss parentheses or have wrong placement.
Final Answer:
SELECT name, (SELECT MAX(score) FROM scores) AS max_score FROM students; -> Option B
Quick Check:
Scalar subquery syntax = parentheses [OK]
Quick Trick:Always put scalar subquery inside parentheses in SELECT [OK]
Common Mistakes:
MISTAKES
Omitting parentheses around subquery
Placing SELECT keyword incorrectly
Using aggregate functions without subquery
Master "Subqueries" in SQL
9 interactive learning modes - each teaches the same concept differently