I coded the following queries:
SomaEntradasTtais:
SELECT artigos.Nome, Sum(Entradas.quantidade_ent) AS [Total Entradas]
FROM artigos INNER JOIN Entradas ON artigos.Cod_artigo = Entradas.Cod_artigo
GROUP BY artigos.Nome;
SomaSaidsTotal:
SELECT Artigos.Nome, Sum(Saidas.quantidade_sai) AS [Total Saidas]
FROM Artigos INNER JOIN Saidas ON Artigos.Cod_artigo = Saidas.cod_artigo
GROUP BY Artigos.Nome;
StockTotal:
SELECT Artigos.cod_artigo, Artigos.Nome, Sum([SomaEntradasTotais]![Total Entradas]-[SomaSaidasTotais]![Total Saidas]) AS Stock
FROM Artigos, SomaEntradasTotais, SomaSaidasTotais
GROUP BY Artigos.cod_artigo, Artigos.Nome;
When the StockTotal query is run containing containing only one article record, it works normally.
EX: Article: a1 - > Tickets: 10 - > Departures: 5 ------------ > Result of the Consultation: Article: a1 -> 5
However when I have 2 or more articles it adds the two and doubles to the two lines
EX:
- Article: a1 - > Tickets: 10 - > Exit: 5
- Article: a2 - > Tickets: 20 - > Exit: 5
- Result of the Consultation: Article: a1 - > 40, Article: a2 - > 40