Hi all,
just looking for general best practice and possibly a rationale for which would be the best way to approach this issue:
I have a query which has 9 individual queries unioned together - the database table design requires this :-(
I need to be able to restrict data into these queries by joining to a seperate table. In terms of speed of execution, am I better off putting the join and criteria in each of the individual queries that are unioned together or as one lump at the end ie this:
etc etc
or like this:
Rgds, Geoff
We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.
Please read FAQ222-2244 before you ask a question
just looking for general best practice and possibly a rationale for which would be the best way to approach this issue:
I have a query which has 9 individual queries unioned together - the database table design requires this :-(
I need to be able to restrict data into these queries by joining to a seperate table. In terms of speed of execution, am I better off putting the join and criteria in each of the individual queries that are unioned together or as one lump at the end ie this:
Code:
SELECT a,b,c FROM t1 INNER JOIN tRef ON t.Key = tRef.key
union
SELECT a,b,c FROM t2 INNER JOIN tRef ON t2.Key = tRef.key
union
SELECT a,b,c FROM t3 INNER JOIN tRef ON t3.Key = tRef.key
or like this:
Code:
SELECT a,b,c FROM (
SELECT a,b,c FROM t1
union
SELECT a,b,c FROM t2
union
SELECT a,b,c FROM t3 ) t
INNER JOIN tRef ON t.Key = tRef.Key
Rgds, Geoff
We could learn a lot from crayons. Some are sharp, some are pretty and some are dull. Some have weird names and all are different colours but they all live in the same box.
Please read FAQ222-2244 before you ask a question