SELECT `id`, MAX(`num`) FROM `table` WHERE `active`=1
SELECT `id`, `query`, WHERE `query`=MAX(`query`)
SELECT `id`, `query`, WHERE `query`=MAX()
SELECT * FROM table t WHERE active = 1 AND NOT EXISTS (
SELECT 1 FROM table WHERE active = 1 AND num > t.num
)