Cristopher Coronado
What is the difference between Union and Union All?
By Cristopher Coronado in SQL on Aug 09 2020
  • Navaneeth Krishnan
    Aug, 2020 12

    Union- It combines two more queries and removes the duplicates.

    UnionAll- It combines two more queries and keeps the duplicates.

    For example: TableA has 1,2,3 and Table B has 3,4,5
    Union Result will be 1,2,3,4,5 (It removes the duplicate 3)
    Union All Result will be 1,2,3,3,4,5 (It keeps the duplicate 3)

    Which one will be faster?
    Union All will be faster, as it does not remove the duplicates.

    • 3
  • Sam Khan
    Aug, 2020 11

    Union All return all rows from tables even duplicate also, however, Union exclude duplicate rows from tables.

    • 1
  • Nisha Regil
    Sep, 2020 11

    UNION: only keeps unique records. UNION ALL: keeps all records, including duplicates

    • 0

Most Popular Job Functions