Reputation: 543
I have a table, which has 9 records with id = 1 - 9 (for example, there can be more than 20 ids).
I have one varchar value = 'premium'.
I need to insert these values to another table, after this action I should have 9 records with id from the first table and 'premium' varchar in the second table:
1, 'premium';
2, 'premium';
etc.
How to write the function for SQL?
Upvotes: 0
Views: 789
Reputation: 23676
Do you want this?
INSERT INTO second_table (id, text_value)
SELECT id, 'premium'
FROM first_table;
Upvotes: 1
Reputation: 1269883
Are you looking for insert . . . select
or create table as
?
insert into table2 (id, value)
select id, 'premium'
from table1;
or:
create table table2 as
select id, 'premium' as value
from table1;
Upvotes: 1