HAVING Clause Example (DAO)

Microsoft Jet SQL Reference

HAVING Clause Example

This example selects the job titles assigned to more than one employee in the Washington region.

This example calls the EnumFields procedure, which you can find in the SELECT statement example.

Sub HavingX()

    Dim dbs As Database, rst As Recordset

    ' Modify this line to include the path to Northwind

    ' on your computer.

    Set dbs = OpenDatabase("Northwind.mdb")

    ' Select the job titles assigned to more than one

    ' employee in the Washington region.

    Set rst = dbs.OpenRecordset("SELECT Title, " _

        & "Count(Title) as Total FROM Employees " _

        & "WHERE Region = 'WA' " _

        & "GROUP BY Title HAVING Count(Title) > 1;")

    

    ' Populate the Recordset.

    rst.MoveLast

    

    ' Call EnumFields to print recordset contents.

    EnumFields rst, 25

    dbs.Close

End Sub