mysql - Display one row for value with multiple categories -
i have table named games
. each game belongs 1 or more categories. have query uses group category_id
returns not desired result. example below, cod
belongs 3 category_id
query shows specific game , omits other games same category_id
. how can achieve below desired query?
query:
select * games group category_id
desired result:
+----------------+--------------------------+ | game_name | category_id | +----------------+--------------------------+ | cod | adventure, fighting, fps | | tekken | fighting | | need speed | racing | +----------------+--------------------------+
use group_concat function
select game_name, group_concat(category_id) categories games group game_name;
good luck!
Comments
Post a Comment