MySQL query to select a record from each group that meets a user-defined criterion
select the record which the highest value for the weight field in each group.

WITH cte AS (SELECT id, categoryID, weight,
                    ROW_NUMBER() OVER (PARTITION BY categoryID ORDER BY weight DESC, id) rn
             FROM sample_table)
SELECT id, categoryID, weight
FROM cte
WHERE rn = 1;

fiddle
I.e. we enumerate rows in a group by categoryID ordering them by weight decrease, then get 1st row in each group.