0

I want to insert data from table1 into table2 and my own data into table2 in one(the same) query, but it is not working. This is my query

$query='insert into table2(id,name) values("001",select first_name from table1 where table1.id="001")';

Please somebody should show me where I am going wrong with my query,I will be very much pleased.Thank you.

Duahs
  • 146
  • 2
  • 3
  • 13

3 Answers3

2
insert into table2 (id, name) 
select '001', first_name 
from table1 
where id = '001'

or you could just use the id since it is 001

insert into table2 (id, name) 
select id, first_name 
from table1 
where id = '001'
juergen d
  • 201,996
  • 37
  • 293
  • 362
1
insert into table2(id,name) 
select "001",first_name from table1 where table1.id="001"
David Jashi
  • 4,490
  • 1
  • 21
  • 26
1
insert into table2 (id, name)
    select id, first_name from table1 where table1.id = '001';

^ why hardcode select '001'?

CodeAngry
  • 12,760
  • 3
  • 50
  • 57