MarkK
bit cruncher
- Local time
- Today, 02:08
- Joined
- Mar 17, 2004
- Messages
- 8,571
I think you could improve performance considerably if you used a series of subqueries rather than a series of union queries. Consider the difference between this...
...and this...
I tested queries almost exactly like those shown above--but with 10 subqueried fields and 10 unions--and the multiple UNION solution took just over twice as long to run.
Code:
[COLOR="Green"]'subqueries deliver data to fields in a main query[/COLOR]
SELECT DISTINCT
( SELECT Count(*) FROM tTestData WHERE ID < 16 ) AS Test1,
( SELECT Count(*) FROM tTestData WHERE ID > 16 ) AS Test2
FROM tTestData;
Code:
[COLOR="Green"]'queries are unioned together. [/COLOR]
SELECT Count(*) FROM tTestData WHERE ID < 16
UNION
SELECT Count(*) FROM tTestData WHERE ID > 16
I tested queries almost exactly like those shown above--but with 10 subqueried fields and 10 unions--and the multiple UNION solution took just over twice as long to run.