insert into select from other table

Posted by user3815079 on Stack Overflow See other posts from Stack Overflow or by user3815079
Published on 2014-08-18T16:18:54Z Indexed on 2014/08/18 16:20 UTC
Read the original article Hit count: 96

Filed under:
|
|

I need to add multiple records based on data from another table where the event is the same. I've found on this forum

insert into table2(id,name) select "001",first_name from table1 where table1.id="001" as possible solution for my question.

So I thought this should be the following syntax:

insert into reservations(event,seat) select "99",id from seats where seats.id>0 

to add all seats to event 99. However when I run this query mysql gives the message 'MySQL returned an empty resultset (0 rows). (query 0.0028 sec)' and no records were added. I translated the message so could be sligthly different.

When I only use the "select "99",id from seats where seats.id>0" query, it returns me 1080 rows.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql