Previous Topic

Next Topic

Book Contents

Book Index

Having Statement

When you are doing a summary query, you can also specify a Having Statement. This is like a Where statement, except that it involves a summary value, rather than a column value.

In the example of customer revenue, the following query shows you customer revenue when it is more than $1000:

SELECT customer_code, month, sum(revenue)

FROM Orders GROUP BY customer_code, month

HAVING sum(revenue) > 1000

Here the HAVING clause has sum(revenue), which can only be determined after the table has been summarized.

Having versus Where

The easiest way to understand the difference between a Where clause and a Having clause is as follows.

Advanced Query Tool
© 2023 Cardett Associates Ltd. All rights reserved.