mysql - Select Top N rows and also handle tie situation -


i want top 3 row table should consider tie situation.

i have table looks this

+--------+---------+ | name   | cost    | +--------+---------+ | ea     | 500     | | spsd   | 475     | | ia     | 450     | | nst    | 450     | | aad    | 350     | | ecom   | 325     | +--------+---------+ 

and desired result should this

+--------+---------+ | name   | cost    | +--------+---------+ | ea     | 500     | | spsd   | 475     | | ia     | 450     | | nst    | 450     | +--------+---------+ 

my query:

select *  table order cost desc limit 0,3 

but returns first 3 rows , doesn't handle if 4th row equal 3rd. how can handle situation query?

use sub-query third highest cost:

select * table cost >= (select cost table                order cost desc                limit 3,1) order c_cost desc 

(i'm not sure limit 3,1 part, since i'm not mysql guy. test , see!)


Comments