Multiple choice

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 clauseQ: An SQL query can contain a HAVING clause only if it has GROUP BY clause R: All attributes used in the GROUP BY clause must appear in the SELECT clauseS: Not all attributes used in the GROUP BY clause need to appear in the SELECT clause

  1. P and R

  2. P and S

  3. Q and R

  4. Q and S

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

We use a HAVING clause without a GROUP BY clause, the HAVING condition applies to all rows that satisfy the search condition. In other words, all rows that satisfy the search condition make up a single group. So, option P is true and Q is false. Function of GROUP BY clause is to group the result obtained using one or more attributes. If attribute name is not present in SELECT clause then GROUP BY cannot find the attribute name in the result according to which result is supposed to be grouped. So, option R is true and S is false.