MYSQL使用Select插入,如果选择返回多于1的值,则插入两者
16lz
2021-01-22
Quite simple but I dont get it. Any Solution?
很简单,但我不明白。任何方案?
For example: if there is 2 times the name peter. But you should insert both.
例如:如果有2倍的名字彼得。但你应该插入两者。
insert into table1 (id,firstname,zip) values ('%s',(select nametable from table2 where name='peter'),'1234');
I hope its understandable
我希望它可以理解
Edit: you get the id.. i just changed it...
编辑:你得到了身份证......我刚改变了......
I want to insert something where I have to select from another table. But the problem is sometimes i get more than 1 result. If there is more than 1 result I want to insert all results.
我想插入一些我必须从另一个表中选择的东西。但问题是有时我得到的结果超过1。如果结果超过1,我想插入所有结果。
1 个解决方案
#1
insert into table1 (id, name, zip) ...
And what would you like to insert into it?
你要插入什么?
... select id, nametable, '1234'
from table2
where name='peter'
Now you connect those 2 pieces and it should work
现在你连接这2件,它应该工作