To avoid updating the rows where the MAX is NULL:
UPDATE test2
SET test2.id= (select max(test1.id) from test1 where test1.bez = test2.bez)
where exists (select 1 from test1 where test1.bez = test2.bez and test1.id is not NULL);
Or to set the ID to 0:
UPDATE test2
SET test2.id= (select NVL(max(test1.id),0) from test1 where test1.bez = test2.bez);
Main Topics
Browse All Topics





by: rramineniPosted on 2003-02-27 at 09:06:26ID: 8035025
How about using nvl function instead of complicating the statements.
UPDATE test2
SET test2.id= (select nvl(max(test1.id),0) from test1 where test1.bez = test2.bez);
or
UPDATE test2
SET test2.id= (select max(nvl(test1.id,0)) from test1 where test1.bez = test2.bez);