In SQL How do I copy values from one table to another based on another field's value?

Posted by Joshua1729 on Stack Overflow See other posts from Stack Overflow or by Joshua1729
Published on 2012-06-03T16:17:43Z Indexed on 2012/06/03 16:40 UTC
Read the original article Hit count: 149

Filed under:
|
|
|

Okay I have two tables

VOUCHERT with the following fields

ACTIVATIONCODE
SERIALNUMBER
VOUCHERDATADBID 
UNAVAILABLEAT   
UNAVAILABLEOPERATORDBID 
AVAILABLEAT 
AVAILABLEOPERATORDBID   
ACTIVATIONCODENEW   
EXT1    
EXT2    
EXT3    
DENOMINATION -- I added this column into the table.

and the second table is VOUCHERDATAT with the following fields

VOUCHERDATADBID
BATCHID
VALUE
CURRENCY
VOUCHERGROUP
EXPIRYDATE
AGENT
EXT1
EXT2
EXT3

What I want to do is copy the corresponding VALUE from VOUCHERDATAT and put it into DENOMINATION of VOUCHERT. The linking between the two is VOUCHERDATADBID. How do I go about it?

It is not a 1:1 mapping. What I mean is there may be 1000 SERIALNUMBERS with a same VOUCHERDATADBID. And that VOUCHERDATADBID has only entry in VOUCHERDATAT, hence one value. Therefore, all serial numbers belonging to a certain VOUCHERDATADBID will have the same value.

Will JOINS work? What type of JOIN should I use? Or is UPDATE table the way to go?

Thanks for the help !!

© Stack Overflow or respective owner

Related posts about sql

Related posts about Oracle