Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009
    Posts
    2

    Unanswered: Update column based on whether a row exists in another column

    Hello,

    I have table T1 with columns (A,B)
    and table T2 with columns (C,D)

    I wanted to do the following in plain english-

    update T1 set B = 'Y'

    if
    exists (select 1 from T2 where T2.C = T1.A)

    else

    update T1 set B = 'N'

    How can I do this in DB2?

  2. #2
    Join Date
    Jan 2003
    Posts
    4,292
    Provided Answers: 5
    Try this:

    Code:
    update t1 set b = case when exists (select 1 from T2 where T2.C = T1.A) then 'Y' else 'N' end
    Andy

  3. #3
    Join Date
    Jan 2009
    Posts
    2
    Thank you!

Posting Permissions

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