SQL - SubqueriesWhich of the following is the correct syntax for a scalar subquery in the SELECT clause?ASELECT col1, (SELECT MAX(col2) FROM table2) AS max_val FROM table1;BSELECT col1 FROM table1 WHERE (SELECT col2 FROM table2);CSELECT col1, SELECT MAX(col2) FROM table2 FROM table1;DSELECT col1, MAX(col2) FROM table1, table2;Check Answer
Step-by-Step SolutionSolution:Step 1: Review scalar subquery syntaxScalar subquery is enclosed in parentheses and used as a column expression.Step 2: Check each optionSELECT col1, (SELECT MAX(col2) FROM table2) AS max_val FROM table1; correctly uses parentheses and alias for scalar subquery in SELECT.Final Answer:SELECT col1, (SELECT MAX(col2) FROM table2) AS max_val FROM table1; -> Option AQuick Check:Correct scalar subquery syntax = SELECT col1, (SELECT MAX(col2) FROM table2) AS max_val FROM table1; [OK]Quick Trick: Scalar subquery must be in parentheses in SELECT [OK]Common Mistakes:MISTAKESOmitting parentheses around subqueryUsing subquery outside SELECT clause incorrectlyMissing alias for scalar subquery column
Master "Subqueries" in SQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More SQL Quizzes Advanced Joins - Natural join and its risks - Quiz 11easy Aggregate Functions - Why aggregation is needed - Quiz 4medium GROUP BY and HAVING - GROUP BY multiple columns - Quiz 4medium INNER JOIN - How the join engine matches rows - Quiz 5medium LEFT and RIGHT JOIN - Why outer joins are needed - Quiz 14medium LEFT and RIGHT JOIN - LEFT JOIN with NULL result rows - Quiz 11easy Subqueries - Subquery in FROM clause (derived table) - Quiz 15hard Table Constraints - FOREIGN KEY constraint - Quiz 12easy Table Relationships - Many-to-many with junction tables - Quiz 14medium Table Relationships - One-to-one relationship design - Quiz 6medium