Get distinct of two columns I want to get distinct of two columns from an SQL table. Can I optimize this query?

create TABLE #Temporary_tbl
(                              
    ProductColour VARCHAR(50),
    ProductSize VARCHAR(20),
)

insert into #Temporary_tbl (ProductColour)
select distinct productcolour
from shoptransfer

insert into #Temporary_tbl (ProductSize)
select distinct ProductSize
from shoptransfer

select * from #Temporary_tbl
This will give you the same result as your sql.

select distinct ProductColour, null as ProductSize
from shoptransfer

union all

select distinct null as ProductColor, ProductSize
from shoptransfer


You don't actually need the "as" clause on the second select, but I find it good for readability.

Ultimatly, sql server will mostly be doing the same thing, but by removing the explicit temporary table and putting it all into one command, you give sql server a better chance of doing the two selects in parallel.