Hi all so I have the following table, 't1'
id r_id o_id count
1 2 100 1
2 3 100 1
3 5 100 1
4 2 101 2
5 3 101 2
6 4 101 2
What I'm trying to do is, for a given list of r_id's, return the r_id and o_id where the count is the highest (max). So ideally, given r_id's of 3 and 5, I would get the following:
r_id o_id
5 100
3 101
I've tried the following:
select o_id, max(count), r_id from t1 where r_id IN (3, 5) group by r_id;
but it doesn't seem to give me the right associated o_id. Any ideas?