Error in GROUP By Clause

  • I have a problem using the group by clause

    this is my T-SQL :SELECT DrugName FROM dbo.tblDrug GROUP BY Category

    GO

    and the error is: Server: Msg 207, Level 16, State 3, Line 1

    Invalid column name 'Category'.

    can you help me ?

  • First it is saying that for object dbo.tblDrug it cannot find a column named 'Category'.

    Secondly there is no Aggregation going on with DrugName so if you correct the Category column issue you will get the following error.

    Server: Msg 8120, Level 16, State 1, Line 1

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

    So step back and consider what you are wanting and make sure you need the group by and not something else.

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

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