0
  Cid  EmpId1 EmpName1 EmpId2 EmpName2
  1    109    Emanuel  256    Sally

select * from emp where cid = 1;

This will query will give me output in horizontal manner. How to get the output in vertical manner using SQL query.

Expected output

Emp1     109
EmpName1 Emanuel
Emp2     256
EmpName2 Sally

I have 50 emp IDs and Emp names in the table as columns. I did not want to go with union all Here is what I tried using unpivot

select Id from (
select Emp1 ,Emp2 from emp where cid = 1) as upvt
Unpivot
(Id for IDs in (Emp1,Emp2))as upvt

How do I include EmpName to this is

Jen K
  • 13
  • 4

0 Answers0