日期:2014-05-18 浏览次数:20654 次
select top 20 * from tblA a,tblB b where a.tblA_user=b.tblA_user and not exists(select 1 from tblB where tblA_user=b.tblA_user and tblB_update>b.tblB_update) order by b.tblB_update desc
------解决方案--------------------
select top 20 m.*,n.* from tblB m , tblA n
where m.tblA_user = n.tblA_user and
tblB_update = (select max(tblB_update) from tblB where tblA_user = m.tblA_user)
order by m.tblB_update desc
select top 20 m.*,n.* from tblB m , tblA n
where m.tblA_user = n.tblA_user and
not exists (select 1 from tblB where tblA_user = m.tblA_user and tblB_update > m.tblB_update)
order by m.tblB_update desc
------解决方案--------------------
我在上面说了这个,你自己没看.
如果不能通过时间确定唯一性,则需要再加上一个字段来判断.
select top 20 m.*,n.* from tblB m , tblA n
where m.tblA_user = n.tblA_user and
not exists (select 1 from tblB where tblA_user = m.tblA_user and (tblB_update > m.tblB_update or (tblB_update = m.tblB_update and fldid > m.fldid)))
order by m.tblB_update desc