I'm trying to set up an SQL command for my virtual store that returns the total value of the request, an item table (requestitemaux), and an additional table for the items (requestitemadaux). I mounted a command, but the error is occurring in Mysql:
Every derived table must have its own alias.
Follow the SQL command:
SELECT
SUM(Total_P + Total_A) AS Total
FROM
(SELECT
Pi.IdItem,
SUM(Pi.Quantidade * Pi.ValorUnit) AS Total_P,
0 AS Total_A
FROM
pedidoitemaux Pi
GROUP BY Pi.IdItem UNION ALL SELECT
Pa.IdItem,
0 AS Total_P,
SUM(Pa.Quantidadead * Pa.Valorad) AS TotalA
FROM
pedidoitemadaux Pa
GROUP BY Pa.IdItem)