Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2005
    Location
    India
    Posts
    217

    Unanswered: Update from a child table

    Code:
    create table rl_1(id int, i int);
    insert into rl_1 (id ) values (1);
    insert into rl_1 (id ) values (2);
    
    create table  rl_2(id int, i int);
    insert into rl_2 values (1,1);
    insert into rl_2 values (2,2);
    
    
    update rl_1 a
    set a.i=
         (select 
         b.i
         from rl_2 b 
         where a.id=b.id
         )
    where exists
           (select 
         b.i
         from rl_2 b 
         where a.id=b.id
         )
    The above code works perfectly. I don't know why the code after "WHERE EXISTS" is required. It seems to be redundant. Any suggestions..?

  2. #2
    Join Date
    Mar 2004
    Location
    Warsaw / Poland
    Posts
    73
    To prevent from updating to null where no value is matched by id.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •