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 table with multiple tables query result

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-29-11, 08:05
anasoul anasoul is offline
Registered User
 
Join Date: Jul 2011
Posts: 2
update table with multiple tables query result

I've got the folloing tables:rashodz, naklrashodz, transport, trans_task_load, shipment_plan.
What I need is to update tbl:rashodz.id_ship whith tbl:shipment_plan.id_ship as follows

rashodz.id2 = shipment_plan.id2 and rashodz.nsthet = naklrashodz.nsthet and naklrashodz.nsthet = trans_task_load.nsthet and shipment_plan.idts = trans_task_load.idts
Just do not have an idea how to do it.
When there are two tables under consideration there is no problem, but how to do it when multiple tables are involved? I would appreciate any help.
Reply With Quote
  #2 (permalink)  
Old 07-29-11, 08:19
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
Something like this?
Code:
update rashodz r set
  r.id_ship = (select s.id_ship
               from shipment_plan s,
                    naklrashodz n,
                    trans_task_load t
               where r.id2 = s.id2
                 and r.nsthet = n.nsthet
                 and n.nsthet = t.nsthet
                 and s.idts = t.idts
              )
  where ...
Reply With Quote
  #3 (permalink)  
Old 07-29-11, 08:28
anasoul anasoul is offline
Registered User
 
Join Date: Jul 2011
Posts: 2
Red face Thanks for your response

This was the first I tried, returns error, that single row query returns moltiple rows.
Reply With Quote
  #4 (permalink)  
Old 07-29-11, 08:57
flyboy flyboy is offline
Registered User
 
Join Date: Mar 2007
Posts: 546
Quote:
Originally Posted by anasoul View Post
This was the first I tried, returns error, that single row query returns moltiple rows.
So, as the error says, the problem is not in the syntax, but in data - either insufficient join conditions or wrong data model/consistency. Unfortunately, Oracle cannot update one column in one row with multiple values - which one should be taken anyway?

This query should return (ID2, NSTHET) values from RASHODZ which would be updated with multiple values (not tested because no test case included):
Code:
select s.id2, n.nsthet, count(*)
from
  shipment_plan s,
  naklrashodz n,
  trans_task_load t
where n.nsthet = t.nsthet
  and s.idts = t.idts
group by s.id2, n.nsthet
having count(*) > 1;
Reply With Quote
Reply

Tags
oracle, pl/sql oracle, sql, update query

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