Updating table from another table

The Oracle UPDATE statement is used to update existing records in a table in an Oracle database.

This blog post illustrates how to update more than one column in a table with values from columns in another table and explains how to do it in the three RDBMS that we support.Table Structures and values: Table A has four columns: a, b, c, d (a is the primary key column) Table B has five columns: a1, b1, c1, d1, e1 (a1 and b1 together constitute the primary key for this table) The foreign key relationship between the two tables is based on A.a = B.a1 The data in these 2 tables is as follows: I. Table B a1 b1 c1 d1 e1 1 x1 y1 z1 40 2 a1 b1 c1 50 The requirement is to write a SQL to update columns b, c and d in Table A from the columns b1, c1 and d1 from Table B where-ever the join condition satisfies and e1 40) / Results after the update: a b c d ———————————— 1 x y z 2 a1 b1 c1 3 t x z SQL Server: UPDATE TABLEA SET b = TABLEB.b1, c = TABLEB.c1, d = TABLEB.d1 FROM TABLEA, TABLEB WHERE TABLEA.a = TABLEB.a1 AND TABLEB.e1 40 GO Note: This is an extension in SQL Server i.e.Even the idea create a temporary table holding only primary key and Column b, and then apply cursor to it is slow. Would u please help me how can i faster my procedure.u have given information 9i it same for oracle8i & dev6i.please help me Thank u very much for ur kind update information is really nice and working very insert----same prolem. That means -- just using math here -- that we have 600 seconds, 12,000 queries to run, 12000/60 = 20, so we are doing 20 per second -- or each query is taking 0.05 cpu seconds to run. do anything 12,000 times and you might have a problem tho! this might be one of the rare times that a temp table can be useful.I am think of the way without using cursor, script as below. I don't understand what's the problem.i am going to give u full overview of my problem. The software is available in different portion of the country for data entry and report generation etc. What about: create global temporary table gtt ( id int primary key, cnt int ) on commit delete rows / you'll add that ONCE, it'll become part of your schema forever....Currently it stores a group of Jobs and each job has a customer listed, however the customer name is stored as a string value and there is a separate "Customer" table that I would prefer to instead of a join of the customer number rather than their name as this causes the data to not be as clean as the user could enter in whatever they like so we could have jobs listed under "ABC Widgets" and "ABC Widgets, Co" and they would appear to be 2 different customers. Customer Name is where I am starting, but I think I am missing something.

I've created a new field in the Jobs table to store the customer ID from the customer table, what I am now trying to figure out is how best to build the query to populate this new field for all the existing jobs (I'll be rewriting the other parts of the code to utilize customer numbers for additions/updates). Most likely a JOIN (which I am still having some trouble fully grasping).

Try searching for similar questions Browse our recent questions Browse our popular tags If you feel something is missing that should be here, contact us.

I inherited a database from an old project and would like to make the data more robust.

The query would in fact execute without any error messages since the correlated subquery in SET clause returns EXACTLY one row for each row in B and the where clause executes without error. Lets say you have a table A ( id int, a1 varchar2(25) ) and a table B ( id int PRIMARY KEY, b1 varchar2(25) ). REGISTRATION(BIN, NAME, NAME_ALIAS, COR_GROUP, AUTHOBY, AUTHODATE, CG_NAME, ADD1, ADD2, ADD3, TEL1, FAX1, ADD5, ADD6, ADD7, TEL2, FAX2, ADD9, ADD10, ADD11, TEL3, FAX3, TP_TYPE, TRD_LINC, TRD_FY, TRD_AUTH, IMP_REG, EXP_REG, REG_TYPE, TIN, STATUS, PRE_BIN, DATREG, STAT_CHNG, ACT_CODE, ACT_MULT, ITEM_TYPE, OLD_ACT, APP_CAT, LCODE, ISSUE_DATE, VREG, M_POSI, MFUNC, SFUNC, LAST_USER, LAST_ACCS, TREG, PAY_FREQ, CREG, EREG, OREG, OP_BAL, OP_BAL_DT) select BIN, NAME---- from VIS. Thank u very much for ur kind & very helpful reply. Here the source tables have data with leading spaces and the target data should be without spaces.

I put a primary key on B(id) because if there is NO SUCH constraint -- the update is totally ambigous -- if there is more then 1 value of B1 in B for a given ID -- we cannot tell what row in B should be used to update the row in A. REGISTRATION where BIN NOT IN (select BIN from VIS. Its working very nicely.i will greateful to u forever.i was suffering by this problem for a long i am using the following / insert into VISTEMP. i could envision problems with only a second of granularity on a clock -- you could miss a record or two due to that. d) I don't program forms -- you can try otn.- Thank u very much for ur nice reply. I plan to use RTRIM function in the WHERE clause to get specific set records and then after fetching, I’ll insert with a RTRIM on each column.

If it is incorrect, then you can get wrong results.