1
Reply

.NET and SQL Server interview questions - Can two different columns be merged into single column? Show practically?

    Answer:

    let's us assume that we have the following table of Employee.

     

    Emp_Id Emp_Name Emp_Salary_2010 Emp_Salary_2011
    1
     
    Shiv 17000 19000
    2
     
    Raju
     
    13500 15000
    3
     
    Sham 15000 18000
    4
     
    Moosa 11000 14000
    5
     
    Feroz 12000 16000
                         
    Now we want to merge the Emp_Salary_2010 and Emp_Salary_2011 columns into a single column as Salary.

    Query:-
     
    select Emp_Name,Emp_Salary_2010 as Salary from Employee
    union
    select Emp_Name,Emp_Salary_2011 as Salary from Employee
    Output:-
     
    Emp_Name Salary
    Shiv 17000
    Shiv 19000
    Raju
     
    13500
    Raju
     
    15000
    Sham
     
    15000
    Sham
     
    18000
    Moosa
     
    11000
    Moosa
     
    14000
    Feroz 12000
    Feroz 15000

    Regards, 

    Please click here to see more .NET and SQL Server interview questions