Syntax error in FROM clause

0

I am trying to add the values that return these two queries in MS Access , and I receive the error

  

"Syntax error in FROM clause"

I have already tried in many ways to achieve the sum of these two queries, someone could tell me what I am wrong about. Thanks

SELECT SUM(SUMA) AS ahorro, generador  FROM (SELECT sum(ahorro) as SUMA, 
generador from kaizen where ESTATUS= 'Cerrado' AND YEAR(fechaValidacion) 
= '2018' and tipoAhorro= 'Hard Perimetral'  GROUP BY generador) + SELECT 
sum(ahorro1) as SUMA,generador from kaizen where ESTATUS= 'Cerrado' AND 
YEAR(fechaValidacion) = '2018' and tipoAhorro1= 'Hard Perimetral' and 
generador GROUP BY generador 
    
asked by M.rivere 04.08.2018 в 21:44
source

1 answer

1

The syntactic error is with the "+" sign of the third line

GROUP BY generador) + SELECT 

You have two ways of doing that:

The first is to make sure you only return a single field for each SELECT, and to group the two subqueries using parentheses

SELECT (SELECT SUM(ahorro1) FROM ...) + (SELECT SUM(ahorro2) FROM ...) AS SUMA

The second one is using the UNION operator instead of the + sign. (See link )

It would be something like:

SELECT SUM(SUMA), Generador
FROM 
(
    SELECT sum(ahorro) as SUMA, generador from kaizen ...
    UNION
    SELECT sum(ahorro) as SUMA, generador from kaizen ...
) GROUP BY generador

One tip to detect syntax errors is to pass your query on validators of this style. link

I hope you get the answer, Greetings

    
answered by 04.08.2018 / 22:24
source