Skip to content
Official PYQ · 2012

GATE CS 2012 Q15 — Tuple Calculus and SQL

Explain with AI

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

Choose one option
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 HAVING clause is designed to filter groups of rows. Conceptually, a GROUP BY clause must be present to define these groups before the HAVING condition 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 BY clause must also appear in the SELECT clause.

Therefore, statements Q and R are true, which corresponds to option C.

Free practice · Your answers on this page are not saved.

Published
Report a correction
Keep exploringMore Tuple Calculus and SQL questions