SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict suzkaw's Avatar
    Join Date
    Apr 2002
    Location
    North Carolina
    Posts
    338
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Access Database COUNT(*) Help.

    I am trying to run this query:
    Code:
    sSQL = "SELECT cartProdID, cartProdName, cartProdPrice, cartQuantity, count(*) AS quantity FROM cart WHERE cartCompleted = '1'  group by cartProdName order by quantity desc"
    And I keep getting this error:

    Microsoft JET Database Engineerror '80040e21'
    You tried to execute a query that does not include the specified expression 'cartProdID' as part of an aggregate function.

    Can you please shed some light on why this is happening?
    Thanks Eric.

  2. #2
    SitePoint Enthusiast
    Join Date
    Apr 2004
    Location
    TX
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, all the items in the select that aren't part of an aggregate function must appear in the group by. The fields in blue you didn't have in the group by, add them in and run your query again, see what you get.
    Code:
    select  cartProdID,
            cartProdName,
            cartProdPrice,
            cartQuantity,
            count(*) AS quantity FROM cart
    where   cartCompleted = '1'
    group   by cartProdID, cartProdName, cartProdPrice, cartQuantity
    order   by quantity desc


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •