Result update from another table

2

I have the following SQL:

SELECT id_grade
      ,MAX(data_lancamento)
  FROM faturamento_produtos
 WHERE data_lancamento < '01-01-2010'
 GROUP BY id_grade

Where it does the search only for what was released before 2010.

I have another table that I want to change a field according to the result of this SELECT .

Summarizing:
I want to put the quantidade_estoque = 0 column of the produto_estoque table to what had a release date prior to 2010.

Both tables have the same id_grade field.

    
asked by anonymous 04.03.2016 / 19:25

1 answer

1

See if that's what I understand ...

update pq
set quantidade_estoque = 0
from produto_estoque pq
join (
        SELECT id_grade,max(data_lancamento) 
        FROM faturamento_produtos 
        where data_lancamento < '01-01-2010' 
        group by id_grade
     )fp
on fp.id_grade = pq.id_grade
    
04.03.2016 / 19:34