Question : Help with MS Access SQL.... UNION syntax question

I need some help. I'm having a small problem with a MS ACCESS query. I think I'm simply having a syntax problem.

SELECT sum(subquery1.balance), subquery1.account FROM
(
SELECT balance, account from table1
UNION ALL
SELECT balance, account from table2
) as subquery1
group by subquery1.balance

If anyone can see something wrong I'd appreciate any feedback.

Thanks,
Ryan

Answer : Help with MS Access SQL.... UNION syntax question

rdorosh,

tpatten is correct. Access does not handle subqueries like Oracle and requires you to create a UNION query first,  then select off of that query like so:

Create union query and save as subquery1(or any name you like):

                  SELECT balance, account from table1
                  UNION ALL
                  SELECT balance, account from table2

Then create a second query that selects the first:
SELECT sum(subquery1.balance), subquery1.account FROM subquery1
                  group by subquery1.account

This should work in Access 97.

Random Solutions  
 
programming4us programming4us