If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Update columns in one table with columns from another

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-14-11, 14:53
ducati321 ducati321 is offline
Registered User
 
Join Date: Jun 2010
Posts: 18
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!
Reply With Quote
  #2 (permalink)  
Old 07-14-11, 15:52
anacedent anacedent is offline
Registered User
 
Join Date: Aug 2003
Location: Where the Surf Meets the Turf @Del Mar, CA
Posts: 6,415
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.
Reply With Quote
  #3 (permalink)  
Old 07-15-11, 01:47
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
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.
Reply With Quote
  #4 (permalink)  
Old 07-15-11, 06:56
ducati321 ducati321 is offline
Registered User
 
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.
Reply With Quote
  #5 (permalink)  
Old 07-15-11, 14:36
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Quote:
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.
Reply With Quote
Reply

Tags
columns, multiple, update

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On