473,495 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Update table with multiple joins

1 New Member
Can anyone tell me how to do this in Oracle?
This is not the exact query but I wanted to simplify it a little. The problem I see is that the WHERE clause depends on the join which I cannot do in Oracle.
------ A
update table1 t1
set t1.pdesc=t2.pdesc, t1.pcost=t3.pcost
from table1 t1 left outer join table2 t2 on t1.name=t2.name
left outer join table3 t3 on t2.product=t3.product
where t1.site='MD' and t1.pdesc is null and t2.pdesc is not null and t1.pcost is null and t3.pcost is not null
------ A
When I try this code below, I get :
ORA-01427: single-row subquery returns more than one row.
------ B
update table1 t1
set (t1.pdesc, t1.pcost)=
(select t2.pdesc, t3.pcost
from table1 t1 left outer join table2 t2 on t1.name=t2.name
left outer join table3 t3 on t2.product=t3.product
where t1.site='MD' and t1.pdesc is null and t2.pdesc is not null
and t1.pcost is null and t3.pcost is not null)
------ B

There will be multiple rows of the same name and product combination but each name and product will only have one pdesc and pcost value.

Thank you!
drahmani
Jun 2 '09 #1
1 4099
QVeen72
1,445 Recognized Expert Top Contributor
Hi,

Break the Query into 2, Update seperately for PDesc and Cost:

update table1 tMain Set (Pdesc) =
(Select t2.pdesc
from table1 t1 left outer join table2 t2 on t1.name=t2.name
where t2.pdesc is not null And T1.Site='MD' And T1.Name = TMain.Name)
Where Site ='MD' And PDesc Is Null


update table1 tMain Set (PCost) =
(Select t3.pcost
from table2 t2 left outer join table3 t3 on t2.product=t3.product
where t3.pcost is not null And T2.Name = TMain.Name)
Where Site ='MD' And PCost Is Null

Regards
Veena
Jun 3 '09 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
248432
by: Dave | last post by:
I have 2 tables, one with names, and another with addresses, joined by their CIVICID number (unique to the ADDRESSINFO table) in Oracle. I need to update a field in the NAMEINFO table for a...
2
2501
by: serge | last post by:
/* This is a long post. You can paste the whole message in the SQL Query Analyzer. I have a scenario where there are records with values pointing to wrong records and I need to fix them using an...
0
4019
by: Alpenk | last post by:
I'm trying to update an empty field in a table using the update statment. The table has a number of joins and the update statement comes up with an error when I enter the main table to update. should...
6
2402
by: Jeff Kowalczyk | last post by:
I need to adapt this an update statement to a general form that will iterate over multiple orderids for a given customerinvoiceid. My first concern is a form that will work for a given orderid,...
10
9799
by: Steve Jorgensen | last post by:
Hi all, Over the years, I have had to keep dealing with the same Access restriction - that you can't update a table in a statement that joins it to another non-updateable query or employs a...
2
2421
by: anony | last post by:
Maybe this feature is already out there. I guess you could write triggers to do some of this. Often when designing a database I add a start_date and end_date column to the table. The start_date...
20
2515
by: p175 | last post by:
Hi people, I have a stored procedure that creates many Global temporary session tables. Into each of these tables go the results of various processing using relational division all keyed and...
2
5633
by: joeyrhyulz | last post by:
Hi, I'm trying to make a very simple update statement (in Oracle) in jet sql that seems much more difficult than it should be. The root of my problem is that I'm trying to update a field on a...
5
4052
by: Bogdan | last post by:
Hi, I have a stored procedure that uses JOINs to return columns from multiple tables. I also have another stored proc that that takes a series of params and updates multiple tables. I used the...
3
2246
by: modernshoggoth | last post by:
G'day all, I'm trying to update a single table (containing plans for flights) with information from the same and other tables (containing info for organisations and locations). tblFlightPlans...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7373
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4897
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4583
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3088
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
286
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.