Skip to main content
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
renjithpl
Specialist
Specialist

Get record holds the highest number

Hi All,

I have a table like this

   

IDRandomNumberCountry
1152Australia
1162Canada

While loading i want

   

IDRandomNumberCountry
1162Canada

to get only one record for an ID with highest RandomNumber. My output should look like

    Any ideas.?

1 Solution

Accepted Solutions
swuehl
MVP
MVP

Both should work.

Working samples:

Table:

LOAD ID, Max(RandomNumber) as RandomNumber, FirstSortedValue(Country, -RandomNumber) as Country

INLINE [

ID, RandomNumber, Country

1, 152, Australia

1, 162, Canada

]

GROUP BY ID;

or

Table:
LOAD * INLINE [

ID, RandomNumber, Country

1, 152, Australia

1, 162, Canada

];

INNER JOIN

LOAD ID, Max(RandomNumber) as RandomNumber

Resident Table

GROUP BY ID;

View solution in original post

5 Replies
swuehl
MVP
MVP

LOAD ID,

         Max(RandomNumber) as RandomNumber,

         FirstSortedValue(Country, -RandomNumber)

FROM ...

GROUP BY ID;

or

Table:

LOAD ID, RandomNumber, Country

FROM ....;

INNER JOIN

LOAD ID, Max(RandomNumber) as RandomNumber

RESIDENT Table

GROUP BY ID;

renjithpl
Specialist
Specialist
Author

I am getting both the records

renjithpl
Specialist
Specialist
Author

The second one is working, let me verify. THanks much.

Not applicable

LOAD *

SQL select

ID ,RandomNumber, Country

from table where RandomNumber=(select max(RandomNumber) from table) ;

try the above


swuehl
MVP
MVP

Both should work.

Working samples:

Table:

LOAD ID, Max(RandomNumber) as RandomNumber, FirstSortedValue(Country, -RandomNumber) as Country

INLINE [

ID, RandomNumber, Country

1, 152, Australia

1, 162, Canada

]

GROUP BY ID;

or

Table:
LOAD * INLINE [

ID, RandomNumber, Country

1, 152, Australia

1, 162, Canada

];

INNER JOIN

LOAD ID, Max(RandomNumber) as RandomNumber

Resident Table

GROUP BY ID;