Was this page helpful?
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Collapse the table of content
Expand the table of content
Expand Minimize

HAVING (Transact-SQL)

Specifies a search condition for a group or an aggregate. HAVING can be used only with the SELECT statement. HAVING is typically used in a GROUP BY clause. When GROUP BY is not used, HAVING behaves like a WHERE clause.

Topic link iconTransact-SQL Syntax Conventions

[ HAVING <search condition> ]


Specifies the search condition for the group or the aggregate to meet.

The text, image, and ntext data types cannot be used in a HAVING clause.

The following example that uses a simple HAVING clause retrieves the total for each SalesOrderID from the SalesOrderDetail table that exceeds $100000.00.

USE AdventureWorks ;
SELECT SalesOrderID, SUM(LineTotal) AS SubTotal
FROM Sales.SalesOrderDetail
HAVING SUM(LineTotal) > 100000.00
ORDER BY SalesOrderID ;

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft