link tables

workers INNER JOIN reviews_of_workers ON workers.id = reviews_of_workers.worker_id 

fields reviews_of_workers, need INSERT for them

 `competence_total` = (@competence_rand := 7+FLOOR(RAND()*4)), `speed_work_total` = (@speed_work_rand := 7+FLOOR(RAND()*4)) 

fields workers, need UPDATE for them

 `reviews_total` = `reviews_total` + 1, `competence` = `competence` + @competence_rand, `speed_work` = `speed_work` + @speed_work_rand 

How to write a query correctly so that each time a line is added to reviews_of_workers (associated with workers ), based on the calculated data, immediately update the data in the associated record of the workers table?

  • Request OR inserts, OR updates. CTE is only SELECT, because it does not support RETURNING. So without options - two requests. If necessary, then in the transaction. - Akina
  • I think you need to write a trigger to insert into the table, which will perform the update of another table - Mike

0