shortysbest Posted January 4, 2011 Share Posted January 4, 2011 This basically select posts from the database (post_id is the id of the post its selecting) and ordering this by the number of rows with this post id in it. How can I order this by amount of posts with this id (as currently), AND by date, newest ones first but in the order of number of them in the database. mysql_query("SELECT post_id, COUNT(post_id) FROM postvoting GROUP BY post_id ORDER BY COUNT(post_id) DESC "); Quote Link to comment https://forums.phpfreaks.com/topic/223391-mysql-order-by-two-different-fields/ Share on other sites More sharing options...
smerny Posted January 4, 2011 Share Posted January 4, 2011 ORDER BY one_thing, another_thing Quote Link to comment https://forums.phpfreaks.com/topic/223391-mysql-order-by-two-different-fields/#findComment-1154776 Share on other sites More sharing options...
shortysbest Posted January 4, 2011 Author Share Posted January 4, 2011 oh, i forgot, I need to order it by the date of the Post_id row in a different table of the same database. I want to order it by the number of rows of the same post_id in the postvoting table, and then order it by the date field in the posts table where the id of the row is equal to post_id in postvoting. Quote Link to comment https://forums.phpfreaks.com/topic/223391-mysql-order-by-two-different-fields/#findComment-1154933 Share on other sites More sharing options...
BLaZuRE Posted January 4, 2011 Share Posted January 4, 2011 You're querying FROM the second table too. Add the ORDER BY as given above. Add a WHERE x.id_1=y.id_2 (x and y are the table names, id_1 and id_2 are the field names) Quote Link to comment https://forums.phpfreaks.com/topic/223391-mysql-order-by-two-different-fields/#findComment-1154950 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.