Condividi tramite


SELECT - SQL Command - HAVING Clause

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.

Tip

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.

Note

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.

    Note

    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.

Note

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

Remarks

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:

See Also

Reference

CREATE QUERY Command
CREATE TABLE - SQL Command
MODIFY QUERY Command

Other Resources

Working with Queries
Working with Views (Visual FoxPro)
Query and View Designers