Skip to content
Advertisement

Insert records into one table using key from another table

I have a table with year, start and end columns like below. It has several years in it. Do not ask me why there is a year called 4 in there because I could not tell you. I just know that it cannot be removed from the table or else the web application will break.

I use this query to insert records into another table.

As you can see 4 is hardcoded in the query. How do I change this query to insert records for all years that are in table1? For example, how do I convert the two queries below into one query using the table with the years in it.

Advertisement

Answer

demo:db<>fiddle

You could use a CROSS JOIN:

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