[英]Multiple Select statements into an Insert statement
I've been searching for a while and I'm not sure if this is allowed in mysql. 我已经搜索了一段时间,但不确定mysql中是否允许这样做。
I know this is allowed in mysql 我知道这是允许在mysql
Insert into 'table' (column1, column2, column3) Select val1, val2, val3 From sometable
Also this 还有这个
Insert into 'table' (column1, column2, column3) Values (val1, val2, val3), (val1, val2, val3)
I am not sure if this is allowed though: 我不确定这是否允许:
Insert into 'table' (column1, column2, column3) Select val1, val2, val3 From sometable, Select val1, val2, val3 From sometable
Obviously that gave me an error, is that allowed in mysql? 显然,这给了我一个错误,在mysql中允许吗?
You can try it, and it will fail. 您可以尝试一下,它将失败。 Use
union all
instead of ,
: 使用
union all
代替,
:
Insert into table (column1, column2, column3)
Select val1, val2, val3 From sometable
union all
Select val1, val2, val3 From sometable;
I assume the single quotes were there for some sort of effect, because you say that the first two queries actually work. 我认为单引号在那里是有某种效果的,因为您说前两个查询确实有效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.