MySQL How do you INSERT INTO a table with a SELECT subquery returning multiple rows?
INSERT INTO Results (People, names ) SELECT d.id, ‘Henry’ FROM Names f JOIN People d ON d.id = f.id Combine the static string Henry with your SELECT query.
INSERT INTO Results (People, names ) SELECT d.id, ‘Henry’ FROM Names f JOIN People d ON d.id = f.id Combine the static string Henry with your SELECT query.
If you’re OK with a SQL command that spreads across multiple lines, then oedo’s suggestion is the easiest: INSERT INTO mytable (myfield) VALUES (‘hi this is some text and this is a linefeed. and another’); I just had a situation where it was preferable to have the SQL statement all on one line, so I … Read more
You simply have to do: INSERT INTO def (catid, title, page, publish) SELECT catid, title, ‘page’,’yes’ from `abc`
The correct syntax is described in the manual. Try this: INSERT INTO this_table_archive (col1, col2, …, coln) SELECT col1, col2, …, coln FROM this_table WHERE entry_date < ‘2011-01-01 00:00:00’; If the id columns is an auto-increment column and you already have some data in both tables then in some cases you may want to omit … Read more