Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2003
    Posts
    6

    Unanswered: compare data in 2 tables and update one table

    dear all,

    I have two tables, table A and Table B

    Table A Table B
    Deliver_id Batch Batch Deliver_id
    WA56789 A3001 A3001 nothing(null)
    WA56789 A3002 A3002 nothing(null)
    WA39058 A1345 A1345 nothing(null)

    These 2 tables is joined by the batch, when the batch = batch.

    I want to take the deliver_id from Table A and insert(update) to Table b.

    WANT

    Table A Table B
    Deliver_id Batch Batch Deliver_id
    WA56789 A3001 A3001 WA56789
    WA56789 A3002 A3002 WA57890
    WA39058 A1345 A1345 WA39058


    I dont know how to write the plsql code or sql code to do this.......

    Please hele me.............


    Greatly greatly appreciated....

  2. #2
    Join Date
    Apr 2003
    Location
    NY
    Posts
    208

    Re: compare data in 2 tables and update one table

    Update TableB B
    Set B.Deliver_id = (Select A.deliver_id
    From TableA A
    Where A.batch = B.batch)

  3. #3
    Join Date
    Jun 2003
    Location
    West Palm Beach, FL
    Posts
    2,713

    Exclamation Re: compare data in 2 tables and update one table

    Originally posted by carloa
    Update TableB B
    Set B.Deliver_id = (Select A.deliver_id
    From TableA A
    Where A.batch = B.batch)
    The following will prevent the deliver_id from table B set to NULL when A.batch does not exist:

    Code:
    
    Update TableB B
    Set B.Deliver_id = (Select A.deliver_id
                                From TableA A
    	            Where A.batch = B.batch) 
    Where EXISTS (
    Select 1
      From TableA A
    Where A.batch = B.batch) 
    
    The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb

Posting Permissions

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