Link to home
Start Free TrialLog in
Avatar of Computer Guy
Computer Guy

asked on

MySQL Syntax

Hi,

I have this:

Group, Genre
General, 80s
General, 90s
Electronic, Techno
Electronic, House

How can I display it like this:

General    80s
                 90s

Electronic
                 Techno
                 House
Avatar of Daniel Wilson
Daniel Wilson
Flag of United States of America image

Display issues (e.g. not repeating a category name) are handled in your front end code (e.g. PHP), not in the MySQL query.
Avatar of Tomas Helgi Johannsson
Hi!

This is what you are looking for.
If the columns of the table is Group and Genre then

select `group`, group_concat(genre, ',' ) 
from table
group by `group`

Open in new window


Note that the word group is a reserved word in all dbms systems so using that in a table or view could lead to parsing errors when executing sql statements.
http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html

Regards,
     Tomas Helgi
Avatar of Computer Guy
Computer Guy

ASKER

Hi, group_concat(genre, ',' )  puts them next to eachother, how can I make them each on their own line?
ASKER CERTIFIED SOLUTION
Avatar of Tomas Helgi Johannsson
Tomas Helgi Johannsson
Flag of Iceland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial