JavaScript Editor js editor     Web development 

Main Page

The HAVING clause specifies conditions that determines the groups included in the query. If the SQL SELECT statement does not contain aggregate functions, you can use a SQL SELECT statement that contains a HAVING clause without a GROUP BY clause.

The HAVING clause without a GROUP BY clause acts like the WHERE clause. If the HAVING clause contains no aggregate functions, use the WHERE clause for faster performance.

The HAVING clause should appear before an INTO clause; otherwise, a syntax error occurs.

For the complete syntax, see SELECT - SQL Command.

The detailed syntax for the HAVING clause is as follows:

HAVING FilterCondition [AND | OR ...]



Specifies criteria that groups must meet for inclusion in the query results. The HAVING clause can include multiple filter conditions connected by AND or OR operators. To reverse the value of a logical expression, use NOT.
Filter conditions in the HAVING clause cannot contain subqueries. You can use local aliases and aggregate functions in the HAVING clause. For more information on aggregate functions in the HAVING clause, see Considerations for SQL SELECT Statements.

For more information about FilterCondition, see the ON clause in the FROM clause.


The following code shows a summary of the main clauses of the SELECT - SQL Command:

В Copy Code
SELECT Select_List
   FROM Table_List
...[WITH (BUFFERING = lExpr)]
   [WHERE Conditions]
   [GROUP BY Column_List]
   [HAVING Conditions]
   [UNION Clause]
   [ORDER BY Column_List]
   [INTO Clause | TO Clause ]

For more information about a particular clause of the SQL SELECT command, see the following topics:

See Also

JavaScript Editor js editor     Web development