I have 3 tables:
- manager with columns:
id serial PK
money int
- facilities_work_data with columns:
id serial PK
income integer
- manager_facilities with colunns:
id serial PK
manager_id references manager(id)
facilities_work_data_id references facilities_work_data(id)
The aim is to update all manager table rows by adding to manager.money column the value from facilities_work_data.income which in turn has to have id column selected as:
SELECT facilities_work_data_id from manager_facilities WHERE manager.id = manager_facilities.manager_id
At least I found the following request:
UPDATE A AS a SET money = a.money + b.income FROM B AS b WHERE b.a_id = a.id
But its not my case, seems like I need one more join.
Could you help with such a request?