Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
rafael5958
Creator
Creator

same id with different names - get longer name

My situation, I have:

id     name
1 jack S
1 jack Soon
1 jack Son
2 Ray J
2 Ray James Charles
2 Ray J C
3 Mark

I need to select only one ID with the longer name, or at lesat only one name. Result something like:

id     name
1 jack Soon
2 Ray James Charles
3 Mark

in SQL I would do something like:

select id,       
max
(name) keep (dense_rank first order by length(name) desc) from t
group by id;

But the table is already loaded in qliview from the database, how would I create a new table with that statement?

Labels (1)
1 Solution

Accepted Solutions
jmartineze
Partner - Creator
Partner - Creator

Hello, change the last line by 

drop tables A, sample;

View solution in original post

5 Replies
jmartineze
Partner - Creator
Partner - Creator

Hello Rafael,

Try something like this

 

A:

Load id, name, length(name) as N 

from "Table";

noconcatenate

B:

load id, max(N)as N  resident  A group by id;

inner join load * resident A;

drop table A;

 

J.

 

rafael5958
Creator
Creator
Author

Didnt work.

It retrives

idN
19
1 
217
2 
34

 

There was not length funcion, only len.

 

sample:

LOAD * INLINE [

id, name    

1,   jack S,
1,   jack Soon,
1,   jack Son,
2,   Ray J,
2,   Ray James Charles,
2,   Ray J C,
3,   Mark ];



A:

Load id,
 name, 
Len(name) as N
resident "sample";
noconcatenate

B:

load id, max(N)as N  resident  A group by id;
inner join load * resident A;
drop table A;

 

jmartineze
Partner - Creator
Partner - Creator

Hello, change the last line by 

drop tables A, sample;

sunny_talwar

You can also try this

sample:
LOAD *,
	 Len(name) as Name_Len;
LOAD * INLINE [
    id, name
    1, jack S
    1, jack Soon
    1, jack Son
    2, Ray J
    2, Ray James Charles
    2, Ray J C
    3, Mark
];

Right Join (sample)
LOAD id,
	 Max(Name_Len) as Name_Len
Resident  sample
Group By id;

DROP Field Name_Len;
rafael5958
Creator
Creator
Author

thank you all, it worked.