Check the performance of this alternative:
select names
from
(
select name, sname, lname from test where sn = 1
) t
unpivot
(
names for col in ( name, sname, lname )
) u
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Consider below case.
One table multiple columns like below .
Table name test .
Create table test ( sn int, name nvarchar(50), sname nvarchar(50), lname nvarchar(50) )
Insert into test Values(1,'aa','bb','cc') ,Values(1,'dd','ee','ff') ,Values(1,'gg','hh','ii') ,Values(2,'jj','kk','ll')
Expected result --all names
query --
Select name from test where sn = 1 union
select sname from test where sn = 1 union
select lname from test where sn = 1
Note:- I have tried UNION ALL as well . not much improvement .
Considering performance issue can we get an alternate solution to this situation in tsql?
Check the performance of this alternative:
select names
from
(
select name, sname, lname from test where sn = 1
) t
unpivot
(
names for col in ( name, sname, lname )
) u