Need to update multiple rows in one table from multiple rows in another
ti3rFeb 22 2013 — edited Feb 23 2013I am coming to conclusion that I can't do this because of the lack of a related unique key, but maybe you can help me with a solution. I have tried all of the solutions posted here but they do not work in my scenario. I have codes in one table that is a list of codes with related market that they are to be used for. I have a second table of customers that do not have the code assigned to them until they are sent an advertisement. That table has the market_id for each customer and the code table has the market_id associated with each code. I want to update the customer table with any one of the mergecodes associated with the market_id - but between the two tables thee is not a unique key to relate. I thought I could just update records that had matching market_ids, but nothing works. From the two tables below I want to be able to update t3tm.mergecode with any one of the mergecodes that has the same market_id ('Austin") in t3mc. it does not matter which one is associated with a particular customer.
{code}
create table T3mc (mergecode varchar(10), market_id varchar(25), week number, used varchar2(5));
Insert into T3mc values ('A8976', 'Austin', 2, '');
Insert into T3mc values ('A8988', 'Austin', 2, '');
Insert into T3mc values ('A9900', 'Houston', 2, '');
commit;
create table T3tm (last_name varchar(20), market_id varchar(25), mergecode varchar(10), id number);
insert into T3tm Values ('Smith', 'Austin', '', 1);
insert into T3tm Values ('Jones', 'Austin', '', 2);
commit;
{code}
{code}
Select * from T3mc;
MARKET_ID, WEEK, USED, MERGECODE
Austin 2 (null) A8976
Austin 2 (null) A8988
Houston 3 (null) A9900
Select * from T3tm;
LAST_NAME, MARKET_ID, MERGECODE ID
Smith Austin (null) 1
Jones Austin (null) 2
{code}