I am not an expert on SQL so please excuse the basic question. I have a table of songs and a table of artists. I want to return songs to thier artists, some songs have more than one artist. I need each song to be returned as one row as I will be binding it to a gridview control asp.net. I know I can JOIN the tables which I have done but how do I return 1 row per a song and both artists in the same row?
Asked
Active
Viewed 134 times
0
-
1Can you post your table structure. Also, I assume it's SQL Server? – Mark Byers Dec 08 '11 at 12:45
-
3Which SQL-dialect? MySQL, SQL-server? – Johan Dec 08 '11 at 12:45
-
How are you going to display the artist(s)? Single column in gridview? – UnhandledExcepSean Dec 08 '11 at 12:53
2 Answers
0
When you write a normal query the artists come in different rows.I suppose you want to transform the rows to columns something like Song Artist1 Artist2 Artist3
For this you can use PIVOT and UNPIVOT operators.Please see this question Rows to Columns

Community
- 1
- 1

Ashley John
- 2,379
- 2
- 21
- 36
-
-1, must wait for the RDBMS brand. 2 user has asked for this information. Also, if you have a solution, write it not only a link. – dani herrera Dec 08 '11 at 13:00
-
@danihp..if you could see the OP has not responded to several questions.and also with the information the OP provided its quite difficult to arrive at solution.And the question seems very duplicate so just pointing to the link is more helpful. – Ashley John Dec 08 '11 at 13:05
-
Luke has previously asked a question on SQLServer, so it might be reasonable to assume that he is using that. – Dec 08 '11 at 13:06
-
@AshleyJohn, OP has only 21R and you 815. You should teach user to make well formed questions. If question is dub, then you should inform about this in a question comment. As you know you can include a link in comments using mini-Markdown formatting. (click help under 'Add Comment' button to learn about. – dani herrera Dec 08 '11 at 13:09
-
@AshleyJohn, yes and johan has asked for this. If AshleyJohn completes the answer I will remove down vote (also system prevent do this if answer is not modified). Really I don't beleave on down votes. – dani herrera Dec 08 '11 at 13:29
0
If you use the SQL server, the answer here seems just what you need: Getting a list of text concatenated in a group by