Jump to content

mysql ORDER BY two different fields


shortysbest

Recommended Posts

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 ");

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.