Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/62.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql SQL:从第一列中选择使用ID插入_Mysql_Select_Insert - Fatal编程技术网

Mysql SQL:从第一列中选择使用ID插入

Mysql SQL:从第一列中选择使用ID插入,mysql,select,insert,Mysql,Select,Insert,我现在有两个表,它们由外键链接 `table_a` ( `table_id` int not null, `important_value varchar(128) not null, ); `table_b` ( `table_id` int not null, `table_a_id` int not null, ) 我想将重要\u值移动到表\u b中,该表引用了表\u a 假设我使用以下altersql alter table `table_b` add

我现在有两个表,它们由外键链接

`table_a` (
    `table_id` int not null,
    `important_value varchar(128) not null,
);

`table_b` (
    `table_id` int not null,
    `table_a_id` int not null,
)
我想将
重要\u值
移动到
表\u b
中,该表引用了
表\u a

假设我使用以下altersql

alter table `table_b` add column `important_value` varchar(128) not null;

如果相关的
重要值
引用了
表a\u id
,我现在如何将其插入
表b
中?

您可以使用
连接

update table_b b join
       table_a a
       on b.table_a_id = a.table_id
    set b.important_value = a.important_value;

侮辱?这几天不是已经太多了吗?该死,你抓到我了。编辑以插入!这很有效。在我接受答复之前,我还有9分钟的时间,但我一定会回程的。谢谢