Collections:
Error: Subquery Returns More than 1 Row in MySQL
What Happens If the UPDATE Subquery Returns Multiple Rows in MySQL?
✍: FYIcenter.com
If a subquery is used in a UPDATE statement, it must return exactly one row for each row in the update table that matches the WHERE clause. If it returns multiple rows, MySQL server will give you an error message. To test this out, you can try the following tutorial exercise:
mysql> INSERT INTO fyi_rates VALUES (0, 'Number 1'); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO fyi_rates VALUES (0, 'Number 2'); Query OK, 1 row affected (0.00 sec) mysql> SELECT * FROM fyi_rates WHERE id = 0; +------+----------+ | id | comment | +------+----------+ | 0 | Number 1 | | 0 | Number 2 | +------+----------+ 2 rows in set (0.00 sec) mysql> UPDATE fyi_links SET notes = ( SELECT comment FROM fyi_rates WHERE fyi_rates.id = fyi_links.id ) WHERE id = 0; ERROR 1242 (21000): Subquery returns more than 1 row
⇒ Deleting an Existing Row from a Table in MySQL
⇐ UPDATE with Subquery Returning No Rows in MySQL
2018-01-08, 6958🔥, 0💬
Popular Posts:
Why I Can Not Enter 0.001 Second in DATETIME values in SQL Server Transact-SQL? If you enter millise...
What is sqlservr.exe - Process - SQL Server (SQLEX?PRESS) in SQL Server? Process sqlservr.exe is the...
How To End a Stored Procedure Properly in SQL Server Transact-SQL? Where the end of the "CREATE PROC...
Where to find tutorials to answer some frequently asked questions on Microsoft SQL Server Transact-S...
What is sqlservr.exe - Process - SQL Server (SQLEX?PRESS) in SQL Server? Process sqlservr.exe is the...