Difficulty: Easy
Correct Answer: Incorrect
Explanation:
Introduction / Context:
Mixing aggregated and non-aggregated columns in a SELECT list requires a GROUP BY clause in standard SQL. Without GROUP BY, only aggregate expressions are allowed (or all selected columns must be functionally dependent according to vendor-specific extensions). This question examines what happens when Name appears alongside COUNT() without GROUP BY.
Given Data / Assumptions:
Concept / Approach:
The query SELECT Name, COUNT() FROM NAME_TABLE; is invalid in standard SQL because Name is neither aggregated nor grouped. Most engines will raise a syntax or semantic error (for example, “column must appear in the GROUP BY clause or be used in an aggregate function”). Furthermore, even if a vendor allowed it with non-standard behavior, the result would not be “a single row and a single column”—the SELECT list clearly has two columns. To correctly count all rows, use SELECT COUNT() FROM NAME_TABLE; To count per name, use SELECT Name, COUNT() FROM NAME_TABLE GROUP BY Name;
Step-by-Step Solution:
Verification / Alternative check:
Test in PostgreSQL or SQL Server—engine rejects the non-grouped, non-aggregated column alongside an aggregate.
Why Other Options Are Wrong:
Common Pitfalls:
Forgetting GROUP BY when mixing aggregate and non-aggregate columns; misreading result shapes.
Final Answer:
Incorrect
Discussion & Comments