Information générale
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
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
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement