I have to flip flight numbers for pairs of flights going back and forth from a set of cities, for example, for example:
1439 ATL SFO
1440 SFO ATL
will end as follows:
1440 ATL SFO
1439 SFO ATL
I tried this query (because you cannot UPDATE .. JOIN in Oracle):
UPDATE
(SELECT f.airline, f.flightno flightno_f, d.airline, d.flightno flightno_d
FROM flights f
INNER JOIN flights d ON f.airline = 9 AND
f.sourceairport = d.destairport AND
f.destairport = d.sourceairport AND d.airline = 9
WHERE d.flightno < f.flightno) g
SET g.flightno_f = g.flightno_d,
g.flightno_d = g.flightno_f;
where is the airline, flightno is the primary key for flying to the table. The selection gives me the correct set of records that I want to change, but UPDATE ... SET gives me this error:
SET g.flightno_f = g.flightno_d,
*
ERROR at line 7:
ORA-01779: cannot modify a column which maps to a non key-preserved table
Any ideas on where I am going wrong?
source
share