Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
http://stackoverflow.com/questions/25033601/write-a-query-to-get-desired-sql-table-output[^] click on the link to get the tables and desired output. This question is asked by a company at technical exam. I could not given answer. Please tell me how can i get the solution.
Posted
Comments
Thanks7872 30-Jul-14 6:38am    
And we are not here to solve puzzles.
ankur15 30-Jul-14 6:54am    
I know we are not here to solve puzzles but here to resolve problems and this is also one problem and technical also.
Thanks7872 30-Jul-14 6:57am    
We help those who have some issue with the code they have implemented themself. Your question is more like home work. We are not here to help you prepare for interview.
Maciej Los 31-Jul-14 6:45am    
There you have got your answer (using CTE)!

SQL
SELECT
M.EMPID
,CASE WHEN M.ID = 1 THEN TA.NAME
      WHEN M.ID = 2 THEN TB.NAME
      WHEN M.ID = 3 THEN TC.NAME
      WHEN M.ID = 4 THEN TD.NAME
FROM
MASTER M
LEFT JOIN TABLEA  TA ON TA.EMPID = M.EMPID
LEFT JOIN TABLEB  TA ON TB.EMPID = M.EMPID
LEFT JOIN TABLEB  TC ON TC.EMPID = M.EMPID
LEFT JOIN TABLEB  TD ON TD.EMPID = M.EMPID
 
Share this answer
 
Comments
Maciej Los 31-Jul-14 6:38am    
Looks good, +5!
We are not here to "do your homework" - and if you can't even be bothered to post the actual question here for us, why should we be bothered to help you either?

If you can't answer, then that tells the company a lot about you. If we answer, that tells the company a lot about us: but it's you that gets the job, not us, and it's us that can do the work, not you.

Try it yourself: it's not exactly complicated!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900