Hai l'idea giusta. Tuttavia, MySQL non garantisce l'ordine di valutazione delle espressioni. Inoltre, hai un group by position
nella sottoquery.
Quindi penso che potresti volere:
SELECT . . .
FROM (SELECT name, surname, position, value, points,
(@num := if(@type = position, @num + 1,
if(@type := position, 1, 1)
)
) AS row_number
FROM players p CROSS JOIN
(SELECT @num := 0, @type := '') params
WHERE (name LIKE '%$searchphrase%' OR surname LIKE '%$searchphrase%') AND
value >= '$minvalue' AND value <= '$maxvalue'
ORDER BY position
) x
WHERE x.row_number <= 2