Ok. I'm still not getting it.
There are different things going on here - selection, grouping and ordering.
Correct me if I'm wrong here:
SELECT determine
which records to return, not how they're returned.
GROUP BY puts like records together in the dataset based on the columns in the GROUP BY clause.
ORER BY sorts them within their groups.
So what does GROUP BY have to do with what records are returned?
>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
>>>
>>>
>>>SELECT Code, SUM(Qty) FROM mytable GROUP BY Code
>>>Result
>>>Code Qty
>>> 1 230
>>> 2 430
>>>
>>>
>>>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"
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people