0

I have the following tables and I want to display all the genres for one game on one row. There is a game table with a GameID and GameTitle:

genre Table

GenreID   Genre_Name   
----------------------
1         Action     
2         Third Person     
3         Open World 

game_genre table

GameGameID   GenreGenreID  
-------------------------
197          1
197          2     
197          3 

This is the result I got:

GameID    GameTitle      Genre 
-------------------------------------  
197       Watch Dogs     Third Person
197       Watch Dogs     Action
197       Watch Dogs     Open World

Query:

SELECT *, GROUP_CONCAT(Genre_Name) 
  FROM game
  JOIN game_genre ON game.GameID = game_genre.GameGameID 
  JOIN genre ON game_genre.GenreGenreID = genre.GenreID`

How do I get a the table to appear like this?

GameID    GameTitle                 Genre 
--------------------------------------------------------------------  
197       Watch Dogs                Third Person, Action, Open World
mrjimoy_05
  • 3,452
  • 9
  • 58
  • 95
user3435395
  • 11
  • 1
  • 4
  • Similar: http://stackoverflow.com/questions/6781103/multiple-rows-to-one-row-query – Noman Ghani Apr 16 '14 at 07:50
  • possible duplicate of [Optimal way to concatenate/aggregate strings](http://stackoverflow.com/questions/13639262/optimal-way-to-concatenate-aggregate-strings) – Saeed Apr 16 '14 at 07:51
  • Just add GROUP_CONCAT(Genre_Name SEPARATOR ', '). Dupe of the first SO comment but not the second. – smoore4 Apr 16 '14 at 08:03

0 Answers0