0

I have 3 tables:

  1. manager with columns:

id serial PK

money int

  1. facilities_work_data with columns:

id serial PK

income integer

  1. 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?

1 Answer 1

1

you can get data from two tables and add the conditions in the where clause like below

update manager M
set money = money + FWD.income
FROM manager_facilities MF,  facilities_work_data FWD
WHERE  M.id = MF.manager_id
AND MF.facilities_work_data_id = FWD.id
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.