------解决方案-------------------- select * from 表1 where ifid in(select objid from (select top 10 objid from 关联表 where visittype in (4,5)) where visittype=4) union all select * from 表2 where ifid in(select objid from (select top 10 objid from 关联表 where visittype in (4,5)) where visittype=5)
------解决方案-------------------- select * from 关联表 left join 表一 on 表一.IFid = 关联表.objID and 关联表.VisitType = 4 left join 表二 on 表二.IFid = 关联表.objID and 关联表.VisitType = 5 where VisitType in (4, 5) and UserID = '' order by VisitType
------解决方案-------------------- SELECT Top(10) ... FROM (
SELECT ... FROM Table_1 T1 ,Table_2 T2 WHERE T1.VisitType = '4' AND T1.ObjID = T2.IFid
Union All
SELECT ... FROM Table_1 T1 ,Table_3 T3 WHERE T1.VisitType = '5' AND T1.ObjID = T3.IFid ) TEM WHERE ... ORDER BY ... 不知道这样怎么样。没写完全。
------解决方案-------------------- (select * from 表1, (select top 10 objid from 关联表 where visittype in (4,5)) as A where 表1.IFid = A.IFid AND A.VisitType=4) union all (select * from 表2, (select top 10 objid from 关联表 where visittype in (4,5)) as A where 表2.IFid = A.IFid AND A.VisitType=5)