Really not sure how to word this. I have two tables, t1 and t2. t1 contains a very long history of messages, so it has [message, t1_id, t2_d]. t2, for the sake of the example just has t2_id. I want to find the message correlated with the highest t1_id. That's easy
where t1_id = (
select MAX(t1_id) as mx
where t2_id = 1
A more efficient solution (probably the most efficient one), using slightly more advanced features.
select t2_id, -- you probably need this! max(t1_id) as max_t1_id, -- if needed max(message) keep (dense_rank last order by t1_id) as message from t1 group by t2_id;