mancroft Posted June 16, 2006 Share Posted June 16, 2006 Sorting problem... session & timeHelloLets say you have data like this:Time Sessionid20.55 x320.44 x320.39 a120.33 a120.29 x320.27 x3and you want to sort it so it looks like this i.e. grouped according to Sessionid and then Time:x3 = 20.55 20.44 20.29 20.27a1 = 20.39 20.33What is the best way to do this in mySQL?Thank you. Quote Link to comment Share on other sites More sharing options...
Wildbug Posted June 16, 2006 Share Posted June 16, 2006 It's easy in MySQL 5.0+ (I think that's when it was added) with the much appreciated GROUP_CONCAT() function. Previous to that function, I'm not sure it's possible in MySQL (you'd have to do it in PHP). Try this:[code]SELECT sessionid,GROUP_CONCAT(time ORDER BY time DESC SEPERATOR ' ') FROM whatever_table GROUP BY sessionid;[/code]See [a href=\"http://dev.mysql.com/doc/refman/5.0/en/group-by-functions.html#id2732618\" target=\"_blank\"]GROUP BY functions[/a] in the manual for more info on options (you can sort the list and specify seperators). Quote Link to comment Share on other sites More sharing options...
mancroft Posted June 16, 2006 Author Share Posted June 16, 2006 Thank you, Wildbug. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.