是否可以执行 1 条 sql 语句(插入),其中您复制了另一个表中的一个插入值和您硬编码的另一个值? 例如,profilepic,我想从另一个表数据中复制值。至于显示名称,我想硬编码。 这是我的 sql 语句:
insert into registration (profilePic, displayname)
values ( (select profilePic from registration where userId = 143), 'abc' );
来自 mysql 的错误信息:
Error code:1093. You can't specify target table 'registration' for update in from clause.
最佳答案
在 values 子句中使用子查询将不起作用。您应该改用以下查询:
insert into registration (profilePic, displayname)
select (select profilePic from registration where userId = 143), 'abc'
关于mysql - 带有嵌套选择的sql插入语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38477699/