表A结构如下:
No Memos
111 AAA
表B的结构如下:
No Seq name
111 1 A
111 2 B
111 3 C要求A同B表关联,且取Seq最大值的数据
结果如下
No Seq Name Memos
111 3 C AAA
No Memos
111 AAA
表B的结构如下:
No Seq name
111 1 A
111 2 B
111 3 C要求A同B表关联,且取Seq最大值的数据
结果如下
No Seq Name Memos
111 3 C AAA
from tableA a join tableB b on a.No = b.No
where not exists(select 1 from tableB where No = b.No and Seq > b.Seq)
from ta a
inner join tb b
on a.no=b.no
inner join
(select no,max(seq) ms from tb group by no) c
on c.no=b.no and c.ms=b.seq