Export (0) Print
Expand All

SELECT - SQL Command - HAVING Clause

Visual Studio 2005

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.

NoteTip

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.

NoteNote

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 ...]

Parameters

FilterCondition

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.

NoteNote

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.

NoteNote

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:

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 ]
   [Additional_Display_Options]

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

Community Additions

ADD
Show:
© 2014 Microsoft