How to select unique rows followed by row with highest value in MySQL? -


i have mysql database table containing information places. i'm trying fetch unique categories followed place highest rating, results returned server not seems accurate.

in database in 1 category can few records scored 100 mysql select 1 have score 95 example.

here query:

select category, score, title places  active = '1' group category order score desc 

is possible in single query?

update

i have rewrote query suggested use mysql function max() returned results still wrong

here example of new query

select category, max(score) maxscore, title, score realscore places  active = '1' group category order score desc 

select category      , max(score) maxscore places active = '1' group category 

if want other fields too, besides category , (maximum) score, can use subquery:

select p.category      , p.score      , p.title      , p.otherfield      , ...     places p   join     ( select category            , max(score) maxscore       places       active = '1'       group category     ) grp     on  grp.category = p.category     , grp.maxscore = p.score p.active = '1' order maxscore desc   

as @zekms pointed, this produce multiple rows (with same category) if there several rows same category , max score.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -