#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2006
    Posts
    365
    Rep Power
    23

    Not contained in either an aggregate function or the GROUP BY


    Hi;

    i am trying sum all the price base on referenceNo, but i get the following error;

    Column 'buyerName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

    my sql statment

    select buyerName, id, category, productName, Sum(price) as "price", date, referenceNo from elena where referenceNo='d11';



    Could anyone help ? Thanks
    Last edited by xbl1; December 14th, 2012 at 11:26 PM.
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,133
    Rep Power
    4274
    to understand this error message, follow along with this logic --

    1. the SELECT clause contains an aggregate function, SUM(price)

    2. the SELECT clause also contains several non-aggregate columns (six of them)

    3. these other six columns must therefore also be in the GROUP BY clause but this is actually missing

    does the error message make sense now?

    put all six of the non-aggregate columns into the GROUP BY clause
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2006
    Posts
    365
    Rep Power
    23
    Thanks a lot, i fix the problem already

IMN logo majestic logo threadwatch logo seochat tools logo