I have two tables - task(id, name) and method(id, max_run) , which are connected by type many-to-many through the table taskmethod(id, task_id, method_id) .

I need to set the field value for the method.max_run entry that matches the desired name task.name

For example, there are related entries:

 task(001, 'MAIN_TASK') taskmethod(1, 001, 005) method(005, 10) 

I imagine a query like this:

 UPDATE method SET max_run = 5 (для записи, для которой task.name = 'MAIN_TASK') 

These are assumptions, since I understand little in SQL. Thanks for the help.

  • one
    where task_id in(select id from task where name='MAIN_TASK') . In general, this is a basic level of knowledge of SQL, it turns out in 1 day and then it is used all my life, it makes sense to study it - Mike
  • As you can see, I didn’t have enough knowledge, studied in one day :) Could you arrange your comment in a separate answer with a full request so that I can accept it as correct? - Vyacheslav Chernyshov
  • Since there is a many-to-many relationship, all the method table entries associated with this task table taskmethod will be updated via the taskmethod table. Do you really need exactly this? - Akina
  • And specify the DBMS — some allow for a multi-table update, some are not. - Akina
  • By the way, Mike, your example does not work. Apparently, one day of learning SQL is still not enough :) - Vyacheslav Chernyshov

1 answer 1

 UPDATE method SET max_run = 5 WHERE id IN (SELECT DISTINCT a.method_id FROM taskmethod a JOIN task b ON a.task_id = b.id WHERE b.name like 'MAIN_TASK') 
  • Thank you for exactly what you need. - Vyacheslav Chernyshov