ted_chou12 Posted February 11, 2007 Share Posted February 11, 2007 I want to organize according to the number of entries, every row has a column value called threadid, which may repeat for different rows, so I wish to put the most frequent appearing threadid on the top, and least at the bottom, is this suppose to be done with GROUP? or something else? Thank you Ted Quote Link to comment https://forums.phpfreaks.com/topic/37992-mysql-how-to-organize-by-the-no-of-rows/ Share on other sites More sharing options...
CrazeD Posted February 11, 2007 Share Posted February 11, 2007 If I understand what you're trying to do, you would put: ORDER BY threadid DESC into your query. You can change DESC to ASC (descending or ascending). Quote Link to comment https://forums.phpfreaks.com/topic/37992-mysql-how-to-organize-by-the-no-of-rows/#findComment-181811 Share on other sites More sharing options...
ted_chou12 Posted February 11, 2007 Author Share Posted February 11, 2007 sorry, I didnt explain clearly enough, I wish to organize the rows by the frequency of the appearance, for example: id threadid 1 2 2 3 3 1 4 2 5 4 so I want the order to look like: 2 (2 comes first because it occured the most frequent.) 3 1 4 the rest would automatically organize by id, since they have the same frequency. Ted Hope that makes it clear Quote Link to comment https://forums.phpfreaks.com/topic/37992-mysql-how-to-organize-by-the-no-of-rows/#findComment-181816 Share on other sites More sharing options...
sasa Posted February 11, 2007 Share Posted February 11, 2007 try SELECT * FROM `table` ORDER BY (SELECT COUNT(`id`) FROM `table` a WHERE a.threadid=table.threadid) DESC Quote Link to comment https://forums.phpfreaks.com/topic/37992-mysql-how-to-organize-by-the-no-of-rows/#findComment-181858 Share on other sites More sharing options...
ted_chou12 Posted February 11, 2007 Author Share Posted February 11, 2007 thanks Quote Link to comment https://forums.phpfreaks.com/topic/37992-mysql-how-to-organize-by-the-no-of-rows/#findComment-181892 Share on other sites More sharing options...
ted_chou12 Posted February 11, 2007 Author Share Posted February 11, 2007 sorry, I have a question, what does a stand for please? Quote Link to comment https://forums.phpfreaks.com/topic/37992-mysql-how-to-organize-by-the-no-of-rows/#findComment-181903 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.