Skip to main content
Announcements
Get Ready. A New Qlik Learning Experience is Coming February 17! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
prayner
Contributor III
Contributor III

SQL select Where in list of strings

I am trying to query a table where specific country codes exist in field 'country_code' from a Redshift db. My solution is shared below, but I feel like it could have better performance:

[tbl1]: 
LOAD
distinct country_code as distinct_country_code // e.g., ='US'
FROM source;

[temp]:
Load
Concat(distinct chr(39) & distinct_country_code & chr(39), ',') as distinct_country_code_str // ='US', 'FR'
Resident tbl1;

LET vCountry_List = Peek('distinct_country_code', 0, 'temp');
drop Table temp;

[tbl2]:
LOAD *;
SELECT *
FROM db.collection
WHERE country_code in ($(vCountry_List)); // Prints as: WHERE country_code in ('US', 'FR');

Any suggestions?

Labels (2)
1 Reply
NiTo
Creator
Creator

Hi, 

Try This:

 

T1:

Load * inline (country_code, US);

Load * from table.qvd where exists(Country_code);

drop t1