MySQL Syntax

Posted on 2014-08-04
Last Modified: 2014-08-08

I have this:

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

How can I display it like this:

General    80s

Question by:Computer Guy
    LVL 32

    Expert Comment

    by:Daniel Wilson
    Display issues (e.g. not repeating a category name) are handled in your front end code (e.g. PHP), not in the MySQL query.
    LVL 24

    Expert Comment

    by:Tomas Helgi Johannsson

    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.

         Tomas Helgi
    LVL 3

    Author Comment

    by:Computer Guy
    Hi, group_concat(genre, ',' )  puts them next to eachother, how can I make them each on their own line?
    LVL 24

    Accepted Solution

    This should do it
    select `group`, group_concat(genre, '\n' ) 
    from table
    group by `group`

    Open in new window

         Tomas Helgi

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    I have been using r1soft Continuous Data Protection ( for many years now with the mySQL Addon and wanted to share a trick I have used several times. For those of us that don't have the luxury of using all transact…
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
    In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor ( If you're interested in additional methods for monitoring bandwidt…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now