Link to home
Start Free TrialLog in
Avatar of MapleMale
MapleMaleFlag for United States of America

asked on

Where to put the Where Clause

This should be a simple question...

I am using UNION to join multiple tables with the same columns. At the end of the my UNION I am aliasing the whole thing as a tableX. After that I have a WHERE statement and a GROUP statement. Efficiency is of great importance! I want to know if it makes a difference from an effeciency standpoint if I repeat the WHERE and GROUP clause with each table in the union, or if I just have it at the end after the alais.
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

the WHERE clause should be per each SELECT.
SELECT ...
  FROM ...
 WHERE ...
 GROUP BY ...
UNION ALL
SELECT ...
  FROM ...
 WHERE ... 
 GROUP BY ...

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of BrandonGalderisi
BrandonGalderisi
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial