Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
hhajjali
Contributor III
Contributor III

Load only first record

Hello,

I have a table which I load in via the following script:

[versions]:

LOAD

[id_u3] AS [id_u3],

[name_u2] AS [name_u2],

[__FK_versions] AS [__KEY_fields]

RESIDENT RestConnectorMasterTable

WHERE NOT IsNull([__FK_versions]) ORDER BY [id_u3];

Each [id_u3] have only one [name_u2] but [__KEY_fields] can have multiple reccord of couple ( [id_u3] , [name_u2]):

Example

[__KEY_fields] id_u3name_u2

1

1TEST1
12TEST2
13TEST3
14TEST4


What I realle need to load in the application for each unique [__KEY_fields] is only the couple ( [id_u3] , [name_u2]) where [id_u3] is the smallest value.

I tried to create a new table in the load script as follow; but it is in error and impossible to launch data load:

[versions1]:

LOAD

FirstSortedValue(id_u3, -Aggr(id_u3, name_u2,[__FK_versions])) as [id_u3],

FirstSortedValue(id_u3, -Aggr(id_u3, name_u2,[__FK_versions])) as [name_u2],

[__FK_versions] AS [__KEY_fields]

RESIDENT [version];

Any ideas ?

Thanks for your help.

1 Solution

Accepted Solutions
hhajjali
Contributor III
Contributor III
Author

Thanks for replies,

First 1 Load * will only load the first record, it is not really what I need, because I want the first record for each [__KEY_FIELDS].

The solution is using firstsortedvalue, Kaushik's response helped me to figure out how to resolve my problem:

First I order my table by [__KEY_fields],[id_u7] :

[versions]:

LOAD

[id_u7] AS [IDVersion],

[name_u4] AS [TEMPRELEASE],

[__FK_versions] AS [__KEY_fields]

RESIDENT RestConnectorMasterTable

WHERE NOT IsNull([__FK_versions])

order by [__KEY_fields],[id_u7];

Then I created another table using fisrtsorted value:

[Release]:

Load

FirstSortedValue([TEMPRELEASE],[IDVersion]) As ARELEASE,

    [__KEY_fields]

RESIDENT [versions]

Group by [__KEY_fields];

View solution in original post

3 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi,

Check this link.

Using FirstSortedValue in the Script

Regards,

Kaushik Solanki

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
ali_hijazi
Partner - Master II
Partner - Master II

First 1 Load *

is this what you mean?

I can walk on water when it freezes
hhajjali
Contributor III
Contributor III
Author

Thanks for replies,

First 1 Load * will only load the first record, it is not really what I need, because I want the first record for each [__KEY_FIELDS].

The solution is using firstsortedvalue, Kaushik's response helped me to figure out how to resolve my problem:

First I order my table by [__KEY_fields],[id_u7] :

[versions]:

LOAD

[id_u7] AS [IDVersion],

[name_u4] AS [TEMPRELEASE],

[__FK_versions] AS [__KEY_fields]

RESIDENT RestConnectorMasterTable

WHERE NOT IsNull([__FK_versions])

order by [__KEY_fields],[id_u7];

Then I created another table using fisrtsorted value:

[Release]:

Load

FirstSortedValue([TEMPRELEASE],[IDVersion]) As ARELEASE,

    [__KEY_fields]

RESIDENT [versions]

Group by [__KEY_fields];