Skip to content
Advertisement

How can I use an input from another table in my query?

I’m creating a new table using PostgreSQL, but I need to get a parameter from another table as an input.

This is the table I have (I called table_1):

id    column_1
1     100
2     100
3     100
4     100
5     100

I want to create a new table, but only using ids that are higher than the highest id from the table above (table_1). Something like this:

insert into table_new
select id, column_1 from  table_old 
where id > (max(id) from table_1)

How can I do this? I tried searching, but I got to several posts like https://community.powerbi.com/t5/Desktop/M-Query-Create-a-table-using-input-from-another-table/td-p/209923, Take one table as input and output using another table BigQuery and sql query needs input from another table, which are not exactly what I need.

Advertisement

Answer

Just use where id > (select max(id) from table_1).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement