2013-07-09 114 views
0

我想從表1中將數據插入到表2中,並將我自己的數據插入到一個(相同)查詢中的表2中,但它不起作用。 這是我的查詢從另一個表中插入數據到mysql表中

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

請應該有人告訴我在哪裏,我跟我的查詢去錯了,我會覺得很pleased.Thank你。

回答

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

,或者你可以只使用id,因爲它是001

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

請我不想從表1中選擇001 – Duahs

+0

是的它工作。謝謝 – Duahs

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

^爲什麼硬編碼select '001'

相關問題