sql - Update table from another table postgresql -
i have 2 tables. table a contains 3 columns: month,code,point while table b contains 5 column:code,point1,point2,point3,point4.
i want update point in table b based on months of table (only 4 months allocated points 1-4).
i assume tablea (code) foreign key tableb (code), , tablea (month,code) unique. take explanation month can 1,2,3 or 4.
update tableb b set      point1 =      (select point tablea       month = 1       , code = b.code),      point2 =      (select point tablea       month = 2       , code = b.code),      (...)      
Comments
Post a Comment