Junaid Junaid - 9 months ago 38
SQL Question

Update Multiple Rows of One Column

I am trying to update multiple rows of one column like below

update persons set salary = (select salary from persons where name = 'John Smith') + 20000;


Here I want to increment all the
persons
's
salary
by 20000 if
name
is John Smith. But I am getting error

ERROR: more than one row returned by a subquery used as an expression
********** Error **********

ERROR: more than one row returned by a subquery used as an expression
SQL state: 21000


I am using Postgresql.

Answer Source

Try this instead:

UPDATE persons 
   SET salary = salary + 20000
WHERE name = 'John Smith';