Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
GROUP BY clause difference between VFP & MSSQL
Message
De
14/09/2000 21:19:36
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00416688
Message ID:
00416710
Vues:
29
>
>>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.
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform