How to Insert Multiple Rows into a Table Using a Select Subquery in MySQL
When attempting to insert data into a table using a SELECT subquery that returns multiple rows, you may encounter the error "Subquery returns more than 1 row." To resolve this issue, you can combine the static string and your SELECT query as follows:
INSERT INTO Results (People, names) SELECT d.id, 'Henry' FROM Names f JOIN People d ON d.id = f.id;
This modification ensures that each row returned by the subquery is combined with the static string 'Henry' before being inserted into the target table. By doing so, you effectively provide a value for the second column (names) for each row, thereby eliminating the error.
The above is the detailed content of How to Resolve the \"Subquery Returns More Than 1 Row\" Error When Inserting Multiple Rows in MySQL?. For more information, please follow other related articles on the PHP Chinese website!