UNION vs UNION ALL | UNION OPERATOR | UNION ALL OPERATOR | UNION Clause|UNION ALL | SQL SET OPERATOR

UNION vs UNION ALL | UNION SET OPERATOR | UNION ALL SET OPERATOR | UNION Clause| UNION ALL Clause | SQL SET OPERATOR | #techpointfundamentals Both UNION and UNION ALL are used to combines the result-set of two or more select queries into a single result-set. The number of columns, order of the columns, and datatype must be the same in both the tables, on which UNION operation is being applied. If we want to sort the results of UNION or UNION ALL the ORDER BY clause should be used on the last SELECT statement. The difference between these two is UNION removes duplicate rows whereas UNION ALL does not. When we use UNION, to remove the duplicate rows, the SQL server has to do a distinct sort which is time-consuming. For this reason, the UNION ALL is much faster than UNION.
Back to Top