I need to update 2 columns in a table with values from another table
UPDATE transakcje t SET s_dzien = s_dzien0, s_cena = s_cena0
FROM
(SELECT c.price AS s_cena0, c.dzien AS s_dzien0 FROM ciagle c
WHERE c.dzien = t.k_dzien ORDER BY s_cena0 DESC LIMIT 1) AS zza;
But I got an error:
plan should not reference subplan's variable.
DB structure is as simple as possible: transakcje
has k_dzien
, k_cena
, s_dzien
, s_cena
and ciagle
has fields price
, dzien
.
I'm running PostgreSQL 9.3.
Edit
I want to update all records from transakcje
.
For each row I must find one row from ciagle
with same dzien
and maximum price
and save this price
and dzien
into transakcje
.
In ciagle
there are many rows with the same dzien
(column is not distinct).