0

Using SQL Select Query with the table of following structure

Id  Name  Subject

07  anu   Maths
07  anu   English
07  anu   Hindi

I want the Result as

Id Name Sub1    Sub2     Sub3
07 Anu  Maths   English  Hindi
2
  • 3
    Welcome to Stack Overflow. This is not a good way to ask a question here. Did you try anything so far to solve your problem? Show your effort first so people might show theirs. Please read FAQ, How to Ask and help center as a start.. Commented May 29, 2014 at 12:00
  • 3
    PIVOT is your friend Commented May 29, 2014 at 12:01

1 Answer 1

1

Try this it will help you

SELECT Name,
      MAX(CASE WHEN Subject = 'Maths' THEN Subject ELSE NULL END) [subject1],
      MAX(CASE WHEN Subject = 'English' THEN Subject ELSE NULL END) [subject2],
      MAX(CASE WHEN Subject = 'Hindi' THEN Subject ELSE NULL END) [subject3]
FROM Subject
GROUP BY Name
Sign up to request clarification or add additional context in comments.

2 Comments

No needed. Would be better as an example solution for question instead of just a link ;)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.