Update through another table - Mysql

0

I have the following problem: I have a rev_tasks table that contains id as a key, and a second rev_reviews table and has a foreign key task_id , pointing to the task, and I have a ( revised ) field review has been revised or not.

In rev_task I have a field ( totalNRev ) that indicates how many NOT reviews have been reviewed

At this point I'm having problems, I have to do an update in the database for all tasks updating the totalNRev field.

Could you give me suggestions? Thanks in advance.

    
asked by anonymous 16.11.2017 / 13:15

1 answer

0

So, guys, I was able to solve here through this update

update rev_tasks t inner join (select task_id, count(1) as qtd from rev_reviews where revisado = 'Nao' group by task_id) r on t.id = r.task_id set t.totalPen = r.qtd where t.id = r.task_id;
    
16.11.2017 / 13:49