Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GROUP BY clause difference between VFP & MSSQL
Message
From
14/09/2000 21:19:36
 
 
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00416688
Message ID:
00416710
Views:
28
>
>>If there is more than one record in the result set, then there is more that one category+id_field combination that has that MIN(mynumber).
>
> Actually this will not help, because what if we need to select all categories? There is solution, however, that is not efficient, using sub-query.

Right.

>(IMHO VFP query in such case MUCH more efficient).

The point is this: If you don't GROUP BY category and id, the ID you get back is meaningless, since it will be the last ID in the table - which will not necessarily be an id that goes with the MIN() value.

e.g.
Category     ID     MyNumber
----------------------------
One          1      3
One          2      4
One          3      3
One          4      3
One          5      5

SELECT category, id, MIN(mynumber) as mynumber ;
  FROM mytable ;
  GROUP BY category ;
  INTO CURSOR cutmp

*returns

Category     ID     MyNumber
----------------------------
One          5      3
Insanity: Doing the same thing over and over and expecting different results.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform