Click here to Skip to main content
15,909,898 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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]
Posted
Updated 20-Apr-19 4:29am
v2
Comments
[no name] 20-Apr-19 10:07am    
Should not a.aprl_fr_dt in(select...) be something like a.aprl_fr_dt = (select...)?
Patrice T 20-Apr-19 10:08am    
And the error is ?

1 solution

There is no GROUP BY option in the UPDATE "syntax" (as indicated).

You do any summing BEFORE; then use the "result set" in the UPDATE.
 
Share this answer
 
Comments
kiran0624 20-Apr-19 12:27pm    
before that i have tried this query

select b.aprl_fr_dt1, max(c.aprl_entdt)
from table_one a, table_two b, table_three c
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;

and successfully got required value, this value i'm trying to update into table_three to that id's(equal condition).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900