Click to See Complete Forum and Search --> : Using a union query as a subquery


hogmahub
May 22nd, 2006, 12:23 PM
I am trying to use two SQL select statements joined using union all as a subquery and Access is not letting me do it. e.g

select t1.customerid, t1.customer, sum(t1.value) as tot from (select SQL1 union all SQL2) t1 group by t1.customerid, t1.customer.

I am passing this through to Access as a VBA / ADO sql string.

Anyone know whether this is possible?

Thanks

Corpse
May 22nd, 2006, 04:33 PM
Not tested, but try this one:

SELECT t1.customerid, t1.customer, sum(t1.value) AS tot
FROM ((SELECT * FROM SQL1) UNION ALL (SELECT * FROM SQL2)) t1
GROUP BY t1.customerid, t1.customer;