SQL update query syntax error

Asked

Viewed 309 times

1

When I run the following update query there is a syntax error before or inside from:

UPDATE Artigos 
SET totale = entradas.sent
FROM Artigos INNER JOIN (SELECT cod_artigo, Sum([quantidade_ent]) AS sent FROM entradas GROUP BY cod_artigo)
ON Artigos.cod_artigo = Entradas.cod_artigo;

I’m using the access

Error message:

syntax error(missing operator) in query expression"tmp.sent FROM Articles INNER JOIN (SELECT cod_article, Sum([quantidade_ent]) AS sent FROM entries GROUP BY cod_article) as tmp ON Articles.cod_article = tmp.cod_article;"

  • Also put the error message. I’ve never seen one either INNER with (SELECT). As far as I know, INNER should specify a table and not a column

  • See here: http://stackoverflow.com/questions/12882212/sql-updating-from-an-inner-join

  • Error message: syntax error(missing operator) in query expression"tmp.sent FROM Articles INNER JOIN (SELECT cod_article, Sum([quantidade_ent]) AS sent FROM GROUP entries BY cod_article) as tmp ON Articles.cod_article = tmp.cod_article;"

2 answers

0

I believe that putting an Alias for the subquery solves.

UPDATE Artigos 
SET Artigos.totale = tmp.sent
FROM Artigos INNER JOIN (SELECT cod_artigo, Sum([quantidade_ent]) AS sent FROM entradas GROUP BY cod_artigo) as tmp
ON Artigos.cod_artigo = tmp.cod_artigo;    
  • didn’t work :(

0

Friend, if I understand your proposal correctly, the following SQL solves your problem:

UPDATE artigos
SET    totale = tmp.sent
FROM   (SELECT  cod_artigo,
            SUM(quantidade_ent) AS sent
   FROM     entradas
   GROUP BY cod_artigo
   )
   tmp
WHERE  tmp.cod_artigo = tmp.cod_artigo;

Browser other questions tagged

You are not signed in. Login or sign up in order to post.