我想從table_a(ptb_registrations)INTO table_b(ptb_users)插入一些列。在表之間移動MySQL行?
目前我有這個查詢從表a中更新表b中的列,而不是覆蓋當前存儲在ptb_users中的現有信息,我希望它插入一個新行。
我的表ptb_users看起來是這樣的:
id (auto inc) | first_name | email
1 john [email protected]
...和我的表ptb_registrations看起來是這樣的:
id (auto inc) | firstname | email
2 eric [email protected]
所以現在我要插入的列名字和ptb_registrations電子郵件到ptb_users.first_name和ptb_users.email作爲新行?
有人可以請指出我在正確的方向嗎?
這部作品更新
$query = "UPDATE ptb_users
SET first_name = (
SELECT firstname
FROM ptb_registrations
)";
mysql_query($query)or die('Could not update members: ' . mysql_error());
我曾嘗試:
$query = "INSERT INTO ptb_users.first_name = (
SELECT firstname
FROM ptb_registrations
)";
mysql_query($query)or die('Could not update members: ' . mysql_error());
什麼是錯誤信息? – jcho360 2013-03-14 16:54:19
你一直想要插入選擇查詢http://dev.mysql.com/doc/refman/5.0/en/insert-select.html你可以在單個查詢中完成所有操作。 – Dave 2013-03-14 16:54:53
我想這是一個「子查詢返回多個行...」 – mimipc 2013-03-14 16:55:14