Which of the following statements are TRUE about an SQL query?
P : An SQL query can contain a HAVING clause even if it does not have a GROUP BY clause
Q : An SQL query can contain a HAVING clause only if it has a GROUP BY clause
R : All attributes used in the GROUP BY clause must appear in the SELECT clause
S : Not all attributes used in the GROUP BY clause need to appear in the SELECT clause
View worked solution
Answer: C
According to standard database textbooks and strict SQL syntax rules often assumed in academic examinations:
- Statement Q is TRUE: The
HAVINGclause is designed to filter groups of rows. Conceptually, aGROUP BYclause must be present to define these groups before theHAVINGcondition can be applied. - Statement R is TRUE: To ensure that the query result is meaningful and each output row is clearly identified by its grouping criteria, all attributes specified in the
GROUP BYclause must also appear in theSELECTclause.
Therefore, statements Q and R are true, which corresponds to option C.
Free practice · Your answers on this page are not saved.
