0

Sql Query:

select Song.name as Song, Band.name as Band        
from Song join BandOnSong on Song.Id = BandOnSong.songId
join Band on BandOnSong.bandId = Band.Id;

Result:

Song              Band
Live Forever      Oasis
Penny Lane        The Beatles
Penny Lane        Test
Where is My Mind  Pixies

Expected Result:

Song              Band
Live Forever      Oasis
Penny Lane        The Beatles, Test
Where is My Mind  Pixies

How can I get the expected result? I tried using a group by on Song.name but I got an error doing that.

Ethan
  • 11
  • 5
  • 1
    Can you tag your question with the database name you use, SQL Server ? MySQL ? The answer will depend of this tag. – Kobi Apr 06 '18 at 08:59
  • https://stackoverflow.com/questions/451415/simulating-group-concat-mysql-function-in-microsoft-sql-server-2005 – jarlh Apr 06 '18 at 09:04
  • I think you also need a field to base the order on. If you don't, you could also get "Test, The Beatles" as a result – Alex Zen Apr 06 '18 at 09:09

0 Answers0