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 7889863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T06:12:23+00:00 2026-06-03T06:12:23+00:00

Basically, I have two tables, one with Some posts on and another for comments,

  • 0

Basically,

I have two tables, one with Some posts on and another for comments, what I am trying to do is create a page with the most popular posts, I will render popular posts depending on how many comments it has.

Here’s the query I have so far

mysql_query("SELECT * FROM posts JOIN comments ON posts.id = comments.content_id ORDER BY count('comments.id') LIMIT 10");

But the count() is messing it up, could anyone help me? THANKS!

  • 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-06-03T06:12:24+00:00Added an answer on June 3, 2026 at 6:12 am

    If you have an aggregate function, such as COUNT(*), you should include a GROUP BY clause:

    Also, since you want to return posts with the most comments, you’ll want to sort by the count in descending order (highest to lowest).

    SELECT 
        posts.id, 
        COUNT(comments.content_id) as post_comments 
    FROM 
        posts 
        LEFT JOIN comments 
            ON posts.id = comments.content_id 
    GROUP BY posts.id
    ORDER BY post_comments DESC
    LIMIT 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically created some tables to play around with: I have Two main tables,
Basically I have a database with two tables, that is, Updates table and Images
I'm building this website and I have basically two questions about this page: http://sites.publishyours.com.br/silviamecozzi/pt/obra/deserto_das_palmas.php
Let's say I have two tables of similar structure, but one is empty and
So, basically, I have a MySQL table called 'topics' and another one called 'replies',
I have two tables: CREATE TABLE [dbo].[Context] ( [Identity] int IDENTITY (1, 1) NOT
Just after some advice regarding this database design situation. So I have two tables
I have a one to many relationship between two tables. The many table contains
I am trying to compare two tables, SQL Server, to verify some data. I
I have two tables, one contains a list of items which is called watch_list

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.