I am using sql server 2008. I have to insert records in temporary table using multiple select statements like below.
Insert into #temp
Select a From TableA
Insert into #temp
Select a From TableB
Insert into #temp
Select a From TableC
Insert into #temp
Select a From TableD
OR
Insert Into #temp
Select A From
(
Select A from TableA
Union
Select B From TableB
Union
Select B From TableC
)K
Please advice which approach should be best or any other and Why?
The two techniques you present are not interchangeable. The
UNIONoperation will remove duplicate values while the individualINSERToperations will not. To get identical results, you’d need to useUNION ALL.