how to check the values in both tables were same or not within postgresql? -


suppose if having 2 table likes leavedata , leavestatus in related columns there (e.g. empid, refno), want make make alterations in leavedata table other columns (i.e. status). how create function checking values both empid , refno in both tables updating status column

sample data  leavedata table  empid    refno     status  no.of days 101        1        pending      4    leavestatus table  empid    refno      check 101          1        null 

it sounds bit might want update ... from, it's hard given sparse detail.

something like:

update leavedata set status = 'approved' leavestatus leavestatus.empid = leavedata.empid    , leavestatus.refno = leavedata.refno   , leavestatus."check" not null; 

massage appropriate; didn't define meanings of leavedata.check, etc i'm hand-waving around those. do not run statement unaltered; use guide understand need do, , remember: always make backups , test statements inside transaction can rollback.

by way, "check" terrible column name; it's reserved word in sql standard, , should not used identifier. you'll have "double quote" everywhere.

in future try describe you're trying achieve bit more, , if possible provide more complete sample data in sqlfiddle this more inserts.


Comments