[英]Insert a row for each result of other query in SQL
If I have two tables with following columns: 如果我有两个带有以下列的表:
Table1: [id,value]
Table2: [id,comment]
where id and value are numeric and comment is a string. 其中id和value是数字,而comment是字符串。
I need to retrieve all the ids with value>50 in the Table1. 我需要检索Table1中值> 50的所有ID。
And make an 然后做一个
INSERT IGNORE INTO table2 VALUES (id,"higher than 50");
for each one of those ids. 对于这些ID中的每个ID。 How can I make it in MySQL?
如何在MySQL中制作? Thanks
谢谢
INSERT IGNORE INTO table2
SELECT id,"higher than 50"
FROM Table1 where value > 50;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.