update one table from two tables records
as im using ingres data base.
E_US0B70 line 1, aggregate function 'max' not allowed in this context.
table_one, table_two and table_three
in table_one i have to update two date columns as query aprl_to_dt and aprl_fr_dt
where aprl_to_dt from table_two as column and aprl_fr_dt from table_three
as records are duplicate so in need max of date should be update in table_one
What I have tried:
i have tried
update table_one a
from table_two b , table_three c
set a.aprl_to_dt= b.aprl_fr_dt1,
a.aprl_fr_dt = max(c.aprl_entdt)
where b.aprl_cmpcd='01' and b.aprl_flag='CNF' and b.aprl_status='ECNF'
and (b.aprl_fr_dt1 is not null or b.aprl_fr_dt1 !='')
and b.aprl_cmpcd =a.aprl_cmpcd
and b.aprl_flag=a.aprl_flag and b.aprl_status = a.aprl_status
and b.aprl_empcd= a.aprl_empcd and b.aprl_due_dt = a.aprl_due_dt
and b.aprl_empcd = c.aprl_empcd and b.aprl_cmpcd = c.aprl_cmpcd and b.aprl_due_dt = c.aprl_incdue
group by b.aprl_empcd, b.aprl_fr_dt1, b.aprl_to_dt1;
i have aslo tried
update table_one a
from table_two b
set a.aprl_to_dt= b.aprl_fr_dt1,
a.aprl_fr_dt in (select max(c.aprl_entdt) from table_three c where
b.aprl_empcd = c.aprl_empcd and b.aprl_cmpcd = c.aprl_cmpcd and b.aprl_due_dt = c.aprl_incdue
group by b.aprl_empcd, b.aprl_fr_dt1, b.aprl_to_dt1)
where b.aprl_cmpcd='01' and b.aprl_flag='CPL' and b.aprl_status='ECPL'
and (b.aprl_fr_dt1 is not null or b.aprl_fr_dt1 !='')
and b.aprl_cmpcd =a.aprl_cmpcd
and b.aprl_flag=a.aprl_flag and b.aprl_status = a.aprl_status
and b.aprl_empcd= a.aprl_empcd and b.aprl_due_dt = a.aprl_due_dt
but
_US09C8 line 1, Syntax error on 'in'. The correct syntax is:
UPDATE table [alias]
[FROM table {, ... }]
SET column = expression|NULL {, ... }
[WHERE search_condition]
or:
UPDATE table [alias]
[FROM table {, ... }]
SET (column,column,...) = (SELECT expr,expr,... FROM ... )
[WHERE search_condition]