Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
ALERT: QlikView server communication interruptions following Microsoft Windows Domain Controller security updates
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.?

Labels (1)
1 Solution

Accepted Solutions
swuehl
Champion III
Champion III

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
Champion III
Champion III

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
Champion III
Champion III

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;