Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
GROUP BY on ORDER BY
Message
De
15/07/2000 15:03:11
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
GROUP BY on ORDER BY
Divers
Thread ID:
00392909
Message ID:
00392909
Vues:
56
I am doing a query on two tables. Multiple records are found in the child table based on the primary key of the master table. I need to only keep one record from the child table. That record is the one on top of the ORDER BY.

If I don't include the GROUP BY, the record I want to keep is always at the top. However, as I only need to keep one record from the child record, I have to put a GROUP BY. When I put, it doesn't take the top record.

SELECT MASTER.MASTERKEY,CHILD.DATE AS CHILDDATE FROM CHILD;
INNER JOIN MASTER ON CHILD.MASTERKEY=MASTER.MASTERKEY;
GROUP BY CHILD.MASTERKEY ORDER BY CHILD.DATE DESCENDING;
INTO CURSOR TEMP

If I don't put the GROUP BY, I'll have something like this:

000001 01/01/2000
000001 12/12/1999
000001 05/06/1999
000001 05/05/1999
000002 01/01/2000
000002 12/11/1999
000002 10/10/1999
000002 09/09/1999

If I put the GROUP BY, I'll have something like this:

000001 05/05/1999
000002 09/09/1999
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform