Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6054007
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:06:15+00:00 2026-05-23T08:06:15+00:00

I am implementing a Popular feature into my app where I will select the

  • 0

I am implementing a Popular feature into my app where I will select the most popular posts from a database. Problem is I need to get the most popular in terms of most likes and most comments. I just tried:

SELECT * FROM db ORDER BY `likesCount`,`commentsCount` DESC LIMIT $from," . ($to-$from)

But that will show an ascending value in terms of the numberOfLikes. How can I get it so that it measures the numberOfLikes and numberOfComments and selects the most popular one?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T08:06:15+00:00Added an answer on May 23, 2026 at 8:06 am

    You can specify whether you want to sort in ascending or descending order for each search field.

    SELECT * FROM `db` ORDER BY `likesCount` DESC, `commentsCount` DESC
    

    With that said, you won’t be able to select the most like and most commented ones at the same time. You’ll have to come up with a formula to figure that out. For instance, the example below find the maximum value for a given “id” between the number of likes and comments:

    SELECT * FROM `db` GROUP BY `id` ORDER BY GREATEST(`likesCount`, `commentsCount`) DESC
    

    Another alternative would be to add them together:

    SELECT * FROM `db` ORDER BY `likesCount` + `commentsCount` DESC
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I implementing OLE DB provider for my custom database. It will be used from
While implementing my own IFilter I found that most likely some consumers will require
Microsoft like implementing their own versions of popular open-source frameworks and assemblies, for example:
I implementing a EventQueue and get notified when AWTEvents are send. I wait till
I'm implementing click tracking from various pages in our corporate intranet in order to
Implementing the very first scala example I ran into some problems probably tipical for
I am having a custom 'tableview' implementation. I am implementing a feature which I
When implementing a microsoft.build.utilities.task how to i get access to the various environmental variables
I`m implementing a custom filesystem on Ubuntu using Fuse, but I need to trap
While implementing the remember me feature for a website, why do we complicate things

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.