Search code examples
subquerymysql-error-1242

I have to update all the rows in a table. Here is my query


UPDATE tracks 
SET People_id_Reference = (SELECT People_id 
                           FROM People 
                           RIGHT JOIN top100 
                           ON 
                           People_name=top100.artist ) 
                           WHERE People_id_Reference IS NULL;

But I get Error like this:

ERROR 1242(21000): SUBQUERY RETURNS MORE THAN ONE ROW

Can some on help me with this. Thanks in advance


Solution

  • The simplest way would be to append a LIMIT 1 onto the end of the subquery to only force it to return a single row.