Why do i see 'subquery returns more than 1 row' in sql?

Example:

UPDATE users SET name = (SELECT name FROM anotherUsers WHERE id = 1);

The subquery used in the SQL statement is returning multiple rows, while the context expects only a single row.

Solution:

Modify the subquery to ensure it returns only one row, or use SQL functions like IN if multiple values are acceptable.


UPDATE users SET name = (SELECT name FROM anotherUsers WHERE id = 1 LIMIT 1);

Beginner's Guide to SQL