Re: Group By Questions...

From: DanHW <danhw_at_aol.com>
Date: 04 Oct 1999 02:35:31 GMT
Message-ID: <19991003223531.17637.00000410_at_ng-cf1.aol.com>


>Hello all,
>
> Assume I have a table with column A, B, C and D.
>
> I wonder the following SQL statements will produce the same results:
>
> i) select B, C, D, avg(A) from AAA group by B, C, D;
> ii) select B, C, D, avg(A) from AAA group by B, D, C;
> iii) select B, C, D, avg(A) from AAA group by C, B, D;
> ....
>
> i.e. does the order of group by clause affect the final result (or
>performance, if any) of the SQL statement? Anyone knows white papers or
>documents discussing this issue?
>
>Thanks,
>Jimmy
>

The sequence of the group by columns makes no difference to the resultant data returned. What the group by does is says 'lump all the rows with the same <group by column> values together, and return the aggregate columns. The fact that a row is different from another row does not depend on the order in which the evaluations are checked.

Strictly speaking, this does not have to be in any particular order. In practice, it **usually** is in normal ascending order since it makes sense to sort them so as new values are discovered in tha data, they can quickly be identified and the data computed. However, to guarantee it, you still need an order by to force the sort. Received on Mon Oct 04 1999 - 04:35:31 CEST

Original text of this message