0

Current syntax:

insert into log_file 
(
    table_id, 
    text, 
    today_date,
    user_id
) 
values 
(
(select id from table where table_no in ('Table1','Table2')),
"Some Text Now",
now(),
143
);

Of course I get the error 'ERROR 1242 (21000): Subquery returns more than 1 row'

How can I accomdate this without having to write out a lot of individual queries?

user3299633
  • 2,971
  • 3
  • 24
  • 38
  • Possible duplicate of [MySQL How do you INSERT INTO a table with a SELECT subquery returning multiple rows?](http://stackoverflow.com/questions/9422529/mysql-how-do-you-insert-into-a-table-with-a-select-subquery-returning-multiple-r) – Gábor Bakos Jan 05 '16 at 17:38

1 Answers1

1

No need to use a subquery, you can use the INSERT...SELECT syntax:

insert into log_file (table_id, text, today_date, user_id)
select id, "Some Text Now", now(), 143
from table
where table_no in ('Table1','Table2')
fthiella
  • 48,073
  • 15
  • 90
  • 106