Database looks like this:
table1
x
id | name
1 | James
2 | Rick
3 | Carl
table2
id | age | gender
<this table is empty>
I want to make a query that passes the same data for all ID’s into table2. So after the query the database would look like the following:
table1
id | name
1 | James
2 | Rick
3 | Carl
table2
id | age | gender
1 | 20 | male
2 | 20 | male
3 | 20 | male
I’ve tried to make some INNER JOIN queries, but I can’t seem to make it work. Any suggestions?
Advertisement
Answer
Do you want this?
insert into table2 (id, age, gender)
select id, 20, 'male'
from table1;
Normally, id
s are defined automatically, so you can probably leave that out:
insert into table2 (age, gender)
select 20, 'male'
from table1;