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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:50:10+00:00 2026-05-26T15:50:10+00:00

Suppose a table of posts, and a table of comments to those posts. The

  • 0

Suppose a table of posts, and a table of comments to those posts. The table ‘comments’ has a column titled ‘post_id’, which holds the id of the target of each comment, and a column titled ‘rating’, which holds the rating for each comment (thumbs up minus thumbs down).

What I need is a query that will select all the posts, together with the HIGHEST RATED comment. An ordinary join, such as the following:

SELECT * FROM posts LEFT JOIN comments ON comments.post_id = posts.id;

…would return one row for each comment. I am guessing that I need to order the table comments by rating, and then group the results by post id. But I’ve been looking for the proper syntax to do so, and couldn’t find it (and trial and error didn’t work either). Any ideas? 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-05-26T15:50:11+00:00Added an answer on May 26, 2026 at 3:50 pm

    This is a classic, see http://dev.mysql.com/doc/refman/5.1/en/example-maximum-column-group-row.html.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose a database table has a column Name which is defined as key for
Suppose I have a table called Companies that has a DepartmentID column. There's also
Suppose we have two tables. Post and Comment. Post has many Comments. Pretend they
Suppose that a table named SuplProd has the columns supplier and product and two
Suppose I have table Person table Employee, which inherits Person. I want to get
Suppose I have a blog post entity. It has many attributes It has comments
In a plugin which shows a table of posts of a custom type, I
Suppose a table named 'users', a table named 'posts' and a table named 'ratings',
Suppose there is a MSSQL table, UserPost , that represents something user has posted,
Suppose I have a tags table with two columns: tagid and contentid . Each

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.