How can I run the SQL like "SELECT * from table where columnA = temp_table_result"?

I have a temp_table defined as:

with temp_table as (
  select id from table_A where name="john" limit 1
)

This table returns 1 row with just the id
I want to select all rows in table_B where the column col_1 is equal to the result of temp_table:

Both of the following fail for me:

select * from table_B where col_1 = temp_table
select * from table_B where col_1 = temp_table.id

>Solution :

SELECT T.*
FROM TABLE_B AS T
JOIN TEMP_TABLE AS A ON T.COL_1=A.ID

Leave a Reply