Home  Fees/Services  Access Examples  Tutorials  Access Download  Articles  Search  Contact  Privacy  Links

Access Query Examples
Having Statement in Aggregate Function Queries
Having with Group By Statement

SQL Having Clause Example SQL Queries

Access Database Tutorials>SQL Queries>Having Clause Basics

Download Access Program


Aggregate Functions
Child/Parent Table Query
Choose Function
SQL Choose Function +
Crosstab/Pivot Query
SQL Crosstab Query +
DateTime Query
SQL Delete Query
External Link to Tables
Filter Report Records
Group By Clause
Having Clause Query
Histogram Query
Insert Into Query/Append
Master/Detail Updates
SQL Order By Dynamic
Parameter Query
SQL Predicate Example
Self Join Query
Access Scalar Query
Select Statement
Select Top 1 Query
Union Query Example
Update Query Example


SQL Having Clause

SQL having clause is a DML (data manipulation language) command used in conjunction with the Group By clause to restrict the records retrieved based on a criteria applied to the aggregate function result values defined in the query.

The basic syntax of the SQL Having clause is:

SQL Having somecriteria

The SQL having clause is optional and is entered as the last clause of a query, after the group by clause.

Select TableName.FieldName1, Count(TableName.Field2),Avg(TableName.Field3) From TableName Where yourcriteria Group By TableName.FieldName1 Having somecriteria

Note: The ending semicolon is a required component of all SQL statements.

Now an SQL Having example with real column and table names:

Select Emp_Name, Sum(iif(Daily_Absence=true,1,0)), Avg(Daily_Hours) From M_Employees Where Work_Date>=#01/01/06# and Work_Date<=#03/31/06# Group By Emp_Name Having Sum(iif(Daily_Absence=true,1,0))>3;

The above query will retrieve unique employees having daily absences days totaling more than 3 during the 1st quarter of 2006 and displays the average daily work hours during the 1st Q.

More SQL Having Clause Examples:

SQL Having with Group By

FieldName1 Having somecriteria. Note: The ending semicolon is a required component of all SQL ... Emp_Name Having Sum(iif(Daily_Absence=true,1,0))>3; ...
www.blueclaw-db.com/accessquerysql/group_by_clause_sql.htm


SQL Having: Update Master Records Based on Detail Record Fields

Having Max(Action_Items.Action_Completed)=-1 " & _ " Group By Task_ID)"). Else. DoCmd.RunSql ("Update Tasks set Task_Complete=False " & _ ...
www.blueclaw-db.com/accessquerysql/master_detail_record_update.htm


 

We now offer web-based SQL/Server application development in partnership with Integrated Databases, Inc. (new projects only).



Contact Information

SQL Queries
MS Access SQL Queries 2007 2003 2000  All Windows Versions