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: 
pietapa
Contributor
Contributor

Select the first rows for SQL Query

Hello guys,
I have a large list of containers that I need to use for my SQL query. However, I keep encountering an error when I try to run the SQL query with the entire list. The error message usually states that a column cannot be found or there are issues with the connection.

To work around this problem, I am looking to retrieve a subset of the containers and use that for my SQL query instead. Specifically, I would like to retrieve the first five or more rows of containers and store them in an array.

However, I am unsure of how to retrieve a subset of rows from the container list. Could you please provide guidance on how I can achieve this?

pietapa_0-1683018974296.png

 

Labels (1)
3 Replies
Kushal_Chawda

@pietapa  assuming you have container list stored somewhere which you can use. I have used first 5 in load to load first 5 values.

 

containers:
LOAD concat(chr(39) & container & chr(39) ,',') as list_container;
first 5 LOAD distinct container
FROM Source;

let vContainerList = peek('list_container',0,'containers');

drop table containers;

then, you can pass the list to SQL query like below

query:
SQL select *
FROM TableName
where container in ('$(vContainerList)');

 

 

pietapa
Contributor
Contributor
Author

Unfortunately, I tried your solution but it does not work... 

VContainerList is still empty...

Kushal_Chawda

@pietapa  Not sure how you are doing it but if you follow same steps it should not generate NULL