Home > Database > Mysql Tutorial > How to Resolve the \'Subquery Returns More Than 1 Row\' Error When Inserting Multiple Rows in MySQL?

How to Resolve the \'Subquery Returns More Than 1 Row\' Error When Inserting Multiple Rows in MySQL?

Patricia Arquette
Release: 2024-10-31 17:24:02
Original
835 people have browsed it

How to Resolve the

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;
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template