What is the difference between `UNION` and `UNION ALL` in terms of performance?

Advanced SQL Developer Medium

Advanced SQL Developer — Medium

What is the difference between `UNION` and `UNION ALL` in terms of performance?

Key points

  • UNION involves sorting and comparing rows for duplicate elimination
  • UNION ALL skips duplicate elimination for faster performance
  • Use UNION when deduplication is necessary; prefer UNION ALL when duplicates are not important
  • UNION ALL is more efficient when duplicates are impossible

Ready to go further?

Related questions