I would like to optimize performance while bringing together queries on many SAS data sets with the same metadata. At this point I have: select * from (select t1.column_a, t1.column_b from table t1) Union (select t2.column_a, t2.column_b from table t2) and so on. Each query brings up unique rows, do I save time wise if I use use Union All instead?
Asked
Active
Viewed 961 times
0
-
1Run it and let us know what you find. – dfundako Jun 28 '16 at 18:53
-
What is the correct **result**? If, unlike your assertion, there *are* duplicate results, should they be in the resultset? That should be your entire criteria. – Damien_The_Unbeliever Jun 28 '16 at 19:06
2 Answers
1
Yes. you are correct. Please refer this. What is the difference between UNION and UNION ALL?
If you are pretty sure that you don't have duplicates, then you can just use the UNION ALL instead of UNION. The later lacks in performance as it has to remove the duplicates

Community
- 1
- 1

Tharsan Sivakumar
- 6,351
- 3
- 19
- 28
0
At some point during UNION there will be checks for duplicates. Even if these checks all turn up false, they are an extra step. UNION ALL will probably be more efficient but as dfundako pointed out, you'll have to test and see to be sure of a difference in speed.

Simon
- 855
- 9
- 24