Chapter 11. SELECT Statement: The HAVING Clause

Introduction

The purpose of the HAVING clause of a select block is comparable to that of the WHERE clause. The difference is that the WHERE clause selects rows after the FROM clause has been processed, whereas the HAVING clause selects rows after a GROUP BY clause has been executed. You can use a HAVING clause only in combination with a GROUP BY clause.

<having clause> ::=
   HAVING <condition>

In the previous chapter, you saw that the GROUP BY clause groups the rows of the result from the FROM clause. The HAVING clause enables you to select groups (with rows) based upon their particular group properties. The condition in the HAVING clause looks a lot like a “normal” condition in the WHERE clause. Nevertheless, ...

Get Introduction to SQL: Mastering the Relational Database Language, Fourth Edition/20th Anniversary Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.