join - Copying data from one table in SQL -


i need update attribute copying info table. problem identify information needed have follow format. update charter table setting char_wait_chg equal results of selecting mod_wait_chg model , aircraft matching mod_code between model , aircraft tables , ac_number between aircraft , charter tables. have charter table contains ac_number , char_wait_chg, aircraft table contains ac_number , mod_code, model table contains mod_code , mod_wait_chg. need make char_wait_chg equal mod_wait_chg, thought use subquery, error ora-01427: single-row subquery returns more 1 row. here have tried:

    update charter      set char_tot_chg=(select mod_wait_chg model join aircraft using(mod_code) join charter using(ac_number)); 

i hope explained enough, appreciated.

this query. subquery returning more 1 row:

update charter      set char_tot_chg = (select mod_wait_chg                         model join                              aircraft                              using(mod_code) join                              charter                              using(ac_number)                        ); 

you have decide how want convert 1 row.

first possibility subquery wrong (because returning rows 3 tables).

if don't mean have different copy of charter in subquery, make correlated subquery no returning rows in tables:

update charter      set char_tot_chg = (select mod_wait_chg                         model join                              aircraft                              using(mod_code)                         charter.ac_number = aircraft.ac_number                        ); 

that might or might not fix problem. still have duplicates , have decide them.

if arbitrary row ok, add:

where rownum = 1 

if want min()/max()/sum()/avg() of value, use:

    set char_tot_chg = (select sum(mod_wait_chg) . . . 

if shouldn't returning duplicates, investigate data more.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

html - Unable to style the color of bullets in a list -

c# - must be a non-abstract type with a public parameterless constructor in redis -