Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Selecting the first one from a group
Message
De
29/02/2000 00:48:15
 
 
À
28/02/2000 23:35:26
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Divers
Thread ID:
00338912
Message ID:
00338949
Vues:
12
This should do it:

SELECT t.PrimaryKey, t.SecondaryKey FROM Table AS t
WHERE t.PrimaryKey IN (SELECT TOP 1 MIN(PrimaryKey) FROM Table WHERE SecondaryKey = t.SecondaryKey)

Vlad

>Assuming I extract two fields from a table. The first field is the primary key and the second field is the secondary key which may occurs more than once in the result.
>
>I would like to have the result to only include the first primary key of the group. Which means, I need to first record of that group which was created.
>
>So, before having the need to group, I had a SQL like this:
>
>SELECT PrimaryKey,SecondaryKey FROM Table INTO CURSOR TEMP
>
>That result would extract several occurences of the same secondary key. So, it may looks like this:
>
>000001 000002
>000002 000002
>000003 000003
>000004 000002
>000005 000002
>000006 000003
>
>I would like to have this:
>
>000001 000002
>000003 000003
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform