Group By with Non-Aggregate Function

  • Hello,

              I want to write one query which has all fields except one field (Numeric) without aggregate function. When I try to do same SQL gives error message that in You must Group By all fields in select list with Aggregate fuction.

           Basic Problem is I want to display one field (Non-Aggregated function) by which I dont wont it to be present in GROUP By clause.

    Please Help me ASAP.

     

     

    --Deepak

     

  • The problem you have is for any column not listed in the group by there are potentially multiple rows (and hence multiople values) in the underlying table, and something has to decide which one of these you want. Logically this is correct - the system cannot start guessing.

    If in your case you *know* that all values in the column you want will actually have the same value per group then simply include this col in an aggregate function such as min or max.

    Mike 

     

  • Please do not cross-post, we monitor all boards.

    Finish the thread here : http://qa.sqlservercentral.com/forums/shwmessage.aspx?forumid=8&messageid=197237

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

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