I need to select some columns from a Amazon Redshift table by storing column_name into a variable using query:-
WITH tmp_variables AS (
SELECT
'Number' AS filter_value,
'required_field2' AS colname1,
'required_field' AS colname2
)
SELECT DISTINCT (SELECT colname1 FROM tmp_variables), (SELECT colname2 FROM tmp_variables)
FROM table_abc where filter_column = (SELECT filter_value FROM tmp_variables);
Here the filter condition is working fine but this is not returning the data as a normal select query gives if I use the variable values directly. What do I need to change here?