Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2010
    Posts
    18

    Unanswered: Update columns in one table with columns from another

    I've been googling for the last hour, and found some things that I thought would work, but have not...

    I have table "revisions", and table "inventory".
    Both have a column "revision".

    I want to update revisions.revision column with inventory.revision, where
    revision.site = inventory.site AND revision.item_no = inventory.item_no

    what i've tried and hasn't worked...

    UPDATE revisions
    SET revisions.revision = i.revision
    FROM revisions, inventory i
    WHERE revisions.site = inventory.site and revisions.item_no = inventory.item_no

    oracle gives error, sql not properly ended

    thanks folks!

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    It is really, Really, REALLY difficult to fix a problem that can not be seen.
    use COPY & PASTE so we can see what you do & how Oracle responds.
    You can lead some folks to knowledge, but you can not make them think.
    The average person thinks he's above average!
    For most folks, they don't know, what they don't know.
    Good judgement comes from experience. Experience comes from bad judgement.

  3. #3
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Something like this might do the job:
    Code:
    update revisions r set
      r.revision = (select i.revision
                    from inventory i
                    where i.site = r.site
                      and i.item_no = r.item_no
                    )
    Additional WHERE clause might be needed to restrict which records should be updated.

  4. #4
    Join Date
    Jun 2010
    Posts
    18
    This was exactly correct. Oddly enough, I tried this earlier and got an error... but when I tried it again, I realized I had made a mistake and not included a clause that would narrow down the inventory table to a single record and it was returning multiple rows, which wouldn't allow the update to happen.

    Thanks for the help!

    Quote Originally Posted by Littlefoot View Post
    Something like this might do the job:
    Code:
    update revisions r set
      r.revision = (select i.revision
                    from inventory i
                    where i.site = r.site
                      and i.item_no = r.item_no
                    )
    Additional WHERE clause might be needed to restrict which records should be updated.

  5. #5
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    I tried this earlier and got an error
    That's why it is important to copy/paste your own SQL*Plus session. Doing so, we'd see what you did and how Oracle responded. Providing assistance is much easier in such a case.

Tags for this Thread

Posting Permissions

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