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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:47:57+00:00 2026-05-30T10:47:57+00:00

This is example of the problem i am having. The query should return rows

  • 0

This is example of the problem i am having. The query should return rows paul and rick because they have the highest rating of the child rows. Instead the query is returning dave and owen, my guess is because they are the first child rows. I am grouping by position and using MAX(child.rating) but the query isn’t working like i want it to be. In the real table i have alot of columns that is why i use child.* in the select clause.

mytable

  id |  name | parentid|  position| rating  |
   1 |  mike |    1    |    1     |    6    |
   2 |  dave |    1    |    2     |    5    |
   3 |  paul |    1    |    2     |    7    |
   4 |  john |    1    |    2     |    3    |
   5 |  mike |    5    |    1     |    8    |
   6 |  owen |    5    |    2     |    2    |
   7 |  rick |    5    |    2     |    9    |
   8 |  jaye |    5    |    2     |    3    |



$getquery = mysql_query("SELECT MAX(child.rating),child.* FROM mytable child 
        LEFT JOIN mytable parent on parent.parentid=child.parentid 
        WHERE parent.name LIKE '%mike%' GROUP BY child.position,child.parentid");



while($row=mysql_fetch_assoc($getquery)) {

 $id = $row['id'];
 $name = $row['name'];
 $parentid = $row['parentid'];



if($id==$parentid) {
    continue;
    }
echo "<p>Name: $name </p>";

}
  • 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-30T10:47:58+00:00Added an answer on May 30, 2026 at 10:47 am

    Funny thing, I’ve just realized what you’re looking for. Here is the final query:

    select t1.* from mytable t1
    left join mytable t2
    on t1.parentid = t2.parentid and t1.rating < t2.rating
    join mytable parents
    on parents.id = t1.parentid
    where t2.rating is null and parents.name like '%mike%'
    

    And here is a working example

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

Sidebar

Related Questions

This is example of the problem i am having. The query should return rows
Here is a (big) example of the massive problem I am having, when this
I have a problem with internet explorer 6 and 7, please look this example
i have problem use link_to_remote link_to_remote document example say link_to_remote Delete this post, :update
im having a problem with a small issue within this query $update = mysql_query(UPDATE
Here's a real noobish MySQL query problem I'm having. I have a high score
This problem is not readily reproducible in a simple example here but was wondering
My example is similar to this - The only problem is I cannot rewrite
This is a contrived example, but it illustrates my problem much more concisely then
This seems like a very simple and a very common problem. The simplest example

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.