Labels

Wednesday, August 24, 2016

UNION and UNION ALL in T-SQL

UNION and UNION ALL


UNION

  1. use to select related information from two or more table
  2. selected column should use same data type
  3. selected column count should be equal
  4. Return DISTINCT value ( remove duplicate records)


UNION ALL

  1. Same as UNION , except that it pull all rows in selected table (which mean it doesn't consider duplicate records).  

If you know that all records are unique , it's better to use UNION , otherwise use UNION ALL



No comments:

Post a Comment