#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2013
    Location
    Paris, France
    Posts
    15
    Rep Power
    0

    GROUP_CONCAT question


    I'm wondering how (if possible) to control the order of the values that go into the GROUP_CONCAT output

    I would like them to be based on an ID number that I have associated with their names ("p_id" which is different from their "id" number)

    When I run the following into MySQL the list seems to be ordered arbitrarily or based on something else

    PHP Code:
    SELECT YearGROUP_CONCAT(CONCAT((LEFT(FName,1)),"."," ",LName)) AS Player
    FROM gg
    WHERE lid 

    GROUP BY Year 
    Thanks in advance!
  2. #2
  3. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,280
    Rep Power
    4279
    Code:
    SELECT Year
         , GROUP_CONCAT(
             CONCAT(LEFT(FName,1),'. ',LName)
             ORDER BY p_id 
                      ) AS Player
      FROM gg
     WHERE lid = 1 
    GROUP 
        BY Year
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

IMN logo majestic logo threadwatch logo seochat tools logo