Inserting Multiple Rows from a SELECT Query into a New Table
When attempting to insert data into a new table using a SELECT subquery that returns multiple rows, MySQL may encounter an error: "Subquery returns more than 1 row". To resolve this issue, consider the following approach:
Solution:
Modify your INSERT statement to combine the static values with the SELECT query. For instance, to populate the Results table with all returning rows:
INSERT INTO Results (People, names) SELECT d.id, "Henry" FROM Names f JOIN People d ON d.id = f.id
By incorporating the static value "Henry" within the SELECT query, MySQL can successfully insert the results into the Results table. This method allows you to insert multiple rows even if the subquery returns an indeterminate number of rows.
The above is the detailed content of How to Insert Multiple Rows from a SELECT Subquery in MySQL?. For more information, please follow other related articles on the PHP Chinese website!