Du har rätt idé. MySQL garanterar dock inte ordningen för utvärdering av uttryck. Dessutom har du en group by position
i underfrågan.
Så jag tror att du kanske vill:
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