simple select - error

  • Hi Team,

    am using below select statement, but getting error

    SELECT id, name, Count(id) AS T FROM testtest

    Error:

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

    Please help

  • The error message is pretty clear, you have a column in the select clause that's not included in a group by clause, as it has to be because of the count.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Minnu (8/9/2013)


    Hi Team,

    am using below select statement, but getting error

    SELECT id, name, Count(id) AS T FROM testtest

    Error:

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

    Please help

    You need to add a GROUP BY for ID and Name.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply