Caroline
Caroline

Reputation: 3913

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.

I need to retrieve all the ids with value>50 in the Table1.

And make an

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

for each one of those ids. How can I make it in MySQL? Thanks

Upvotes: 2

Views: 750

Answers (1)

Andrej
Andrej

Reputation: 7504

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

Upvotes: 4

Related Questions