0

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?

2 Answers2

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