Results 1 to 2 of 2
  1. #1
    Join Date
    Jun 2007
    Posts
    17

    Unanswered: Comparing two rows in sybase

    Hi,
    I have a table with the following data

    Col A Col B Col C Col D
    100 A Y Null
    100 A N Null
    100 B N Null
    100 B N Null

    Col A has value 100 in all rows, col B has values A, A, B, B respectively, col C has values Y, N, N , N respectively and col D contains Null

    I want to update col D to the value 'Yes' if the two rows in Col B match but their corr. values in col C don't. For instance, consider the first two rows:
    In both the rows col B has the value A but col C has values Y and N respectively. So Col D for both of these rows should be updated to 'Yes'. But, third and 4th rows have the same value B in col B and same value N in Col C, so Col D for these rows should not be updated.

    How can I do it using a single update query?

    Thanks
    Sajita...
    Last edited by sajita; 07-25-07 at 10:57.

  2. #2
    Join Date
    Aug 2002
    Location
    Madrid, Spain
    Posts
    97
    Not tested:

    update MYTABLE set II.D='Yes'
    from MYTABLE I, MYTABLE II
    where I.A=100
    and II.A=100
    and I.B = II.B
    and I.C <> II.C

    Regards,
    Mariano Corral

Posting Permissions

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