Union Vs Union All Final

Опубликовано: 01 Август 2021
на канале: DataGuru Naval
55
1

For database related videos, please subscribe channel
   / @datagurunaval  

UNION and UNION ALL are SQL operators used to concatenate 2 or more result sets. This allows us to write multiple SELECT statements, retrieve the desired results, then combine them together into a final, unified set.
We need to take care of following points to write a query with the SQL Union Operator.
• Both the Select statement must have the same number of columns
• The columns retrieved must be of similar data types.
• Column Order must also match in both the Select statement
• We can define Group By and Having clause with each Select statement. It is not possible to use them with the result set
• We cannot use Order By clause with individual Select statement. We can use it with result set generated from the Union of both Select statements. the ORDER BY clause must be at the end of the query