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分钟的时间,但我一定会回程的。谢谢