SQL Questions and Answers – SQL Having Clause

This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Having Clause”.

1. Which clause is used in SQL to specify a filter condition for a group?
a) Where
b) Group by
c) Having
d) Filter
View Answer

Answer: c
Explanation: The HAVING clause is used with the GROUP BY clause to specify a filter condition for a group or an aggregate. HAVING clause places conditions on groups created by the GROUP BY clause.

2. HAVING clause can be used with which of the following statements?
a) Update
b) Select
c) Delete
d) Insert
View Answer

Answer: b
Explanation: The HAVING clause places conditions on groups created by the GROUP BY clause. It can be used with the SELECT statement only.

3. Which of the following order is valid in SQL?
a) Where, Having, Group By, Order By
b) Where, Group By, Order By, Having
c) Group By, Where, Having, Order By
d) Where, Group By, Having, Order By
View Answer

Answer: d
Explanation: If a SELECT query contain WHERE or HAVING clauses, then the WHERE clause must appear before the GROUP BY clause and the HAVING clause must appear after it but before the ORDER BY clause.
advertisement
advertisement

4. A SELECT statement cannot contain both WHERE and HAVING clauses in a single query.
a) True
b) False
View Answer

Answer: b
Explanation: A SELECT query can contain both a WHERE and a HAVING clause, but in that case WHERE must appear before GROUP BY and HAVING must appear after GROUP BY.

5. HAVING clause is used in combination with which of the following clause(s)?
a) Where
b) Order by
c) Group by
d) Select
View Answer

Answer: c
Explanation: SQL HAVING clause is used in combination with the GROUP BY clause to restrict the groups of returned rows to only those whose the condition is TRUE.

6. A HAVING clause works like a WHERE clause if it is not used with the GROUP BY clause.
a) True
b) False
View Answer

Answer: a
Explanation: In the absence of GROUP BY clause, the HAVING clause works like a WHERE clause. The difference between the HAVING and the WHERE clause is that the WHERE clause is used to filter rows, while the HAVING clause is used to filter groups of rows.

Sanfoundry Global Education & Learning Series – SQL.

advertisement

To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.