How can i get top result of each group in MYSQL

Votes : 3.2
1153
I wrote mysql query statement has selecting data with group by clause. That query already work, but expected result was not in there. SELECT * FROM TABLE GROUP BY group_id ORDER BY salary DESC ; Return very first lower id ( ASC order ) recode of each group. But i need get best salary in each group. How can i do this by using only mysql single statment.

Your Answer

1 Answer

answered
Re-write the query like this:
SELECT * FROM ( SELECT * FROM table_name ORDER BY salary DESC ) AS tbl GROUP BY group_id;

What is the codrate ?

codrate.com is a standard, fast cross browsing and highly versatile site. It is useful for many large number of Program Development Industries. So you can get support form Codrators , who are the codrate's joiners around world to help your program developments, You can answer other codrator's questions. Communicate with them. Share your knowledge with them. Do you have an interest in programming, So publish your articles about programming. It will help to maintain your professional co-profile. Actually codrate.com is not such as a regular web site. It will be gave new experience, best narrow cross-browser view, reduce processing time to receive browsing request, it's mean do not wasting your time to browsing codrate's web pages because it has been upgrade always modern coding ways. So, what do you waiting for ?. Try your own.

Copyright 2015 Pride - Company. Design by Esila