2011-08-20 54 views
2

其他查詢的每個結果。如果我有兩個表具有以下的列:插入一行在SQL

Table1: [id,value] 
Table2: [id,comment] 

其中id和值是數字和註釋是一個字符串。

我需要檢索Table1中值> 50的所有id。

並作出

INSERT IGNORE INTO table2 VALUES (id,"higher than 50"); 

對於這些ID的每一個。我如何在MySQL中創建它?謝謝

回答

4
INSERT IGNORE INTO table2 
SELECT id,"higher than 50" 
FROM Table1 where value > 50;