The query I use for the join is : WITH temp_cte AS (SELECT partition_date, appstate.viewid FROM table1 WHERE partition_date = \'2020-10-10\') SELECT * FROM temp_cte AS