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

Announcements
Qlik Named a 7-Time Gartner® Magic Quadrant™ Leader: See the 2026 Report
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sub-query in Qlik sense

Hello All,

Someone please help me. How can I create a load statement for the following SQL query.

select LocationId,MainVesselId FROM [dbo].[tbl_Data_VesselActivity] where SlNo in (select max(SlNo) FROM [dbo].[tbl_Data_VesselActivity] group by MainVesselId).


Please help. It's urgent.


Thank You,


Rahul

Labels (1)
4 Replies
arulsettu
Master III
Master III

try like this

load LocationId,

    MainVesselId,

    max(SlNo)

from tbl_Data_VesselActivity

group by LocationId,MainVesselId;

saimahasan
Partner - Creator III
Partner - Creator III

Hi

Please try this:

A:

load * Inline [

SlNo,LocationId,MainVesselId

10,a,58

12,b,34

12,c,45

24,a,56

24,b,81

12,c,78

21,a,45

];

B:

LOAD  max(SlNo) as MaxSlNo

Resident A;

LET a = Peek('MaxSlNo',0,'B');

C:

LOAD *,

  '' as jnk

Resident A

Where SlNo = $(a);

DROP Tables A,B;

Not applicable
Author

Thanks for the suggestion.

But, loop is required to consider all values.

This is taking on one value, i,e. max. value

Please help.

saimahasan
Partner - Creator III
Partner - Creator III

You can try this code:

A:

load * Inline [

SlNo,LocationId,MainVesselId

10,a,58

12,b,58

12,c,58

24,a,56

24,b,56

12,c,56

21,a,47

];

B:

LOAD  MainVesselId as A1,

   max(SlNo) as MaxSlNo

Resident A

Group By MainVesselId;

C:

LOAD * ,

  '' as jnk

Resident A

Where Exists(MaxSlNo,SlNo);

DROP Table A;

It will give the output as

LocationId MainVesselId SlNo
a4721
a5624
b5624
b5812
c5612
c5812

Is this your requirement??