Results 1 to 4 of 4
  1. #1
    vicki is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2014
    Posts
    5

    Having V.S. Where

    Hi,



    is there any different from having and where? Which one is more efficiency? - thx

    SELECT testedYear, Count(testedDate) AS countOfTestedDate
    FROM results
    GROUP BY testedYear
    HAVING testedYear=2014




    SELECT testedYear, Count(testedDate) AS countOfTestedDate
    FROM results
    where testedYear=2014
    GROUP BY testedYear

  2. #2
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Here is an description with samples.

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    I actually don't like that description, though it's technically true. The WHERE clause is applied before the aggregation, the HAVING clause is applied after (which is why WHERE can't use the aggregate functions; they haven't been done yet). Using your SQL, the WHERE clause should be more efficient. The HAVING clause would pull all records, perform the count, then only return 2014. The WHERE clause would only pull 2014 records, then perform the count and return the records. On smaller databases you probably wouldn't see a difference, but in larger ones you could.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    I'm not saying it's the best example -- it was quick; relatively simple; and most comments were very positive.
    I could not find an example from Simply SQL (can't find a link at the moment).

Please reply to this thread with any new information or opinions.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums