If you only need ONE of the ids that contains the MAX(amt), then this will do the trick:
SELECT id, name, MAX(amt)
FROM sample
WHERE amt BETWEEN 1000 AND 5000
GROUP BY name;
If you need all the ids, then it gets more complicated. Two queries are required, plus a temporary table:
CREATE TEMPORARY TABLE maxamts
SELECT name AS maxname, MAX(amt) AS maxamt
FROM sample
WHERE amt BETWEEN 1000 AND 5000
GROUP BY maxname;
SELECT GROUP_CONCAT(id), maxname AS name, maxamt AS amt
FROM maxamts
LEFT JOIN sample ON ((maxname = sample.name) AND (maxamt = amt))
GROUP BY maxname;
In short: Create a temporary table from the query that finds each name/max(amt) pair, then use that temporary table to join back on the original table and pull out the IDs matching the name/amount combinations.
Just remember that group_concat is by default limited to 1,024 characters, (show variables like '%group_concat%'
to see the max length on your server), so if you've got a large dataset, increase that limit, or remove the group_concat and group by from the second query and parse the information in your application.