ticket_number | some_id
99 | 55551
99 | 56447
99 | 79857
74 | 84892
74 | 78141
74 | 12569
SELECT ticket_number, some_id
FROM (
SELECT ticket_number, some_id,
rank() OVER (PARTITION BY ticket_number ORDER BY some_id DESC) RnkDESK,
rank() OVER (PARTITION BY ticket_number ORDER BY some_id ASC) RnkASC
FROM table ) x
WHERE X.RnkDESK = 1 OR X.RnkASC = 1