Now I want to run update so Joe's salary and dept should be equal to other Joe which is 500 and 20, and Kelly's salary should be equal to other kelly's salary and dept.
I Have over 2000 rows that needs to be update, so I have to to run single statement.
SQL> select * from xyz;
ID NAME SAL
---------- -------------------- ----------
1 joe
2 sally
3 pete
4 pete 2222
5 joe 3333
6 sally 7777
7 kelly 4444
7 rows selected.
SQL> update xyz x
set sal = (
select max(sal)
from xyz y
where sal is not null and y.name = x.name)
/
7 rows updated.
SQL> select * from xyz;
ID NAME SAL
---------- -------------------- ----------
1 joe 3333
2 sally 7777
3 pete 2222
4 pete 2222
5 joe 3333
6 sally 7777
7 kelly 4444
7 rows selected.
Bookmarks