Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Incorrect Syntax Error
Message
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
01323625
Message ID:
01324367
Views:
16
There's no ORDER BY in the query and even if there was one, it's applied after GROUP BY not before.


>In the query #2 from wich record do you expect result value for Descript would come from for each group? SQL Engine does not have this info and cannot proceed.
>
>The question of 'which record' is answered by the WHERE clause, is it not? I always thought GROUP BY determined the physical order of the records in the result set, not which records are returned.
>
>So in your example #2, since, you said 'ORDER BY Code', then record #1 would be first, then record #2, based off the values in the code field.
>
>I don't see what I'm missing.
>
>
>>
>>Table: mytable
>>Code Descript Qty
>>  1  One      110
>>  1  OneOne   120
>>  2  Two      210
>>  2  Two      220
>>
>>-- #1
>>SELECT Code, SUM(Qty) FROM mytable GROUP BY Code
>>Result
>>Code Qty
>>  1  230
>>  2  430
>>
>>-- #2
>>SELECT Code, Descript, SUM(Qty) FROM mytable GROUP BY Code
>>Result
>>Code Descript  Qty
>>  1  ?         230
>>  2  ?         430
>>
>>
>>>
>>>"....than SQL engine wouldn't know what record it should come from"
--sb--
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform