Reference Guide > TDV SQL Keywords and Syntax > HAVING
 
HAVING
The HAVING clause is used in combination with GROUP BY. You can use HAVING in a SELECT statement to filter the records that a GROUP BY returns.
Syntax
GROUP BY column1, ... column_n
HAVING condition1 ... condition_n;
Example
SELECT OrderID, SUM (orderdetails.Quantity) sumQuantity
FROM /shared/examples/ds_orders/orderdetails
GROUP BY OrderID
HAVING SUM (orderdetails.Quantity) > 10
 
The example has 50 unique OrderID values. SUM (orderdetails.Quantity) returns 296, but adding the GROUP BY clause causes the results to have a separate SUM (quantity) value. HAVING SUM adds a filter to that result set.