sql - How to select MAX value in field based on another field -
i have query (oracle query returning results linked server sql table) returns results this: -
personid | encounterno | location ---------+-------------+----------- 123456 | 1 | london 123456 | 2 | manchester 123456 | 3 | glasgow 246810 | 1 | liverpool 246810 | 2 | newcastle 357911 | 1 | edinburgh 357911 | 2 | aberdeen 357911 | 3 | dublin
i select max
value each personid
output be: -
personid | encounterno | location ---------+-------------+------------- 123456 | 3 | glasgow 246810 | 2 | newcastle 357911 | 3 | dublin
select t.* table t inner join ( select t.personid, max(t.encounterno) table t group t.personid ) j on t1.personid = j.personid , t.encounterno = j.encounterno
Comments
Post a Comment