Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    50

    Arrow Unanswered: update statement

    Hi,
    I want to do something like below. Plz lemme know how can this be achieved..

    update x
    set x.a = y.a
    x.b = y.b
    where x.c = y.c

    (y is another table)

    Thnx
    Ishan

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Would this work?

    Code:
    UPDATE x SET
    (x.a, x.b) = 
    	(SELECT y.a, y.b 
    	 FROM y 
    	 WHERE y.c = x.c
    
    );

    Last edited by Littlefoot; 05-12-04 at 09:48.

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    update x
    set (x.a, x.b) = (select y.a, y.b from y where x.c = y.c)
    where exists (select null from y where x.c = y.c);

    The WHERE clause on the update is there to prevent a and b being set to NULL when no matching y record is found. If you would want them set NULL, remove the WHERE clause!

  4. #4
    Join Date
    Mar 2004
    Posts
    50
    ya.. it worked..

    Thanks
    Ishan

  5. #5
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Ah, where exists ... I always learn something new from you, Tony. 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
  •