Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Selecting the first one from a group
Message
From
29/02/2000 00:48:15
 
 
To
28/02/2000 23:35:26
General information
Forum:
Visual FoxPro
Category:
Databases,Tables, Views, Indexing and SQL syntax
Miscellaneous
Thread ID:
00338912
Message ID:
00338949
Views:
10
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
Previous
Reply
Map
View

Click here to load this message in the networking platform