Anda memiliki ide yang tepat. Namun, MySQL tidak menjamin urutan evaluasi ekspresi. Plus, Anda memiliki group by position
di subkueri.
Jadi saya rasa Anda mungkin ingin:
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