MySQL: LIMIT by a percentage of the amount of records?

Best answer I found:

SELECT*
FROM    (
    SELECT list.*, @counter := @counter +1 AS counter
    FROM (select @counter:=0) AS initvar, list
    ORDER BY value DESC   
) AS X
where counter <= (10/100 * @counter);
ORDER BY value DESC

Change the 10 to get a different percentage.

Leave a Comment