skip to Main Content

I am on phpmyadmin, and I have data:

query url score  
a www.google.com 3  
a www.facebook.com 2  
a www.google.com 1

I want to ‘group’ entries by their domain, and then order (desc) the domain groups by each group’s highest score (some in the comments have found this wording clearer: ‘order desc by each group’s highest score’) so I get:

query url score  
a www.google.com 3  
a www.google.com 1
a www.facebook.com 2  

Trying: select * from table order by score desc, url asc doesnt work. It gives (no apparent change):

query url score  
a www.google.com 3  
a www.facebook.com 2  
a www.google.com 1

I’m apparently not communicating my troubles clearly. If you can see where I can make it clearer, let me know.

For reference, I have re-posed the question here and it has an accepted answer: How do I order groups by each group's highest value

2

Answers


  1. If i understand, you want order by var1 first as asc and then by var2 as desc.

    What about this:

    SELECT * FROM table ORDER BY var1 ASC, var2 DESC;
    
    Login or Signup to reply.
  2. According to your expected output, you don’t need grouping at all, just a multiple column order by clause:

    SELECT   *
    FROM     mytable
    ORDER BY var1 ASC, var2 DESC
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search