1

I want to retrieve a table which has repeated values in column1, column2 and column3. column 4 has different sets of data corresponding to value in column3. How should I query such a table?

Ex:

District  | City           | Place 
----------|----------------|-------------
bangalore | bangalorerural | indiranagar
bangalore | bangalorerural | jayanagar

I want to display bangalore, bangalorerural once with indiranagar and jayanagar in other rows.

3
  • Not sure it can be done into a table but you can get a similar structure by returning xml Commented Mar 18, 2011 at 10:17
  • Plese provide desired output. I understand that data provided in the question is table from which you'd like to get data and not the result. If it's the other way around, then provide an example table data. I can't really say whether you'd like to concatenate column3 or something else... Commented Mar 18, 2011 at 11:18
  • 1
    Please give an example of the output Commented Mar 18, 2011 at 13:22

1 Answer 1

3

UNPIVOT is what you're after

http://archive.msdn.microsoft.com/SQLExamples/Wiki/View.aspx?title=UNPIVOTData

Sign up to request clarification or add additional context in comments.

2 Comments

I understand that the question is vague, but... how can it be about UNPIVOT? What have you deduced is to be unpivoted here?
Bangalore need to be displayed once. i.e. an UNPIVOT. I'm only going with what I figure the asker is asking. I think they need to clarify by giving an example of the output now I've re-read

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.