select a.*,b.* from TN_PROCESS_ROUTES, (select t.* from TN_PROCESS_ROUTE t where id = (select max(id) from TN_PROCESS_ROUTE where [OBJECT_ID] = t.OBJECT_ID)) b where a.[OBJECT_ID] = b.[OBJECT_ID]
create table #t1 (id int ,nnn1 int) insert #t1 select 1,2 union all select 2,2 union all select 3,2 union all select 4,2 create table #t2 (id int ,nnn2 int) insert #t2 select 1,3 union all select 2,3 union all select 3,3 union all select 4,3 select a.*,b.nnn2 from #t1 a join #t2 b on a.id= b.iddrop table #t1 drop table #t2
(select t.* from TN_PROCESS_ROUTE t where id = (select max(id) from TN_PROCESS_ROUTE where [OBJECT_ID] = t.OBJECT_ID)) b
where a.[OBJECT_ID] = b.[OBJECT_ID]
insert #t1 select 1,2
union all select 2,2
union all select 3,2
union all select 4,2
create table #t2 (id int ,nnn2 int)
insert #t2 select 1,3
union all select 2,3
union all select 3,3
union all select 4,3
select a.*,b.nnn2 from #t1 a join #t2 b on a.id= b.iddrop table #t1
drop table #t2