这条查询语句有问题,只能显示500条以内的数据(不管新的还是旧的)超过500后新的数据就不显示了,Sql="Select  * from (select top 1000 isbest,istop,logid,postid,topic,author,replys,lastupdate From oblog_teampost Where teamid=" & Group_id & " And iDepth=0 And isTop=1 " & SqlPart & " Order By Lastupdate Desc"
  Sql= Sql & " union "  Sql= Sql & " Select  top 1000 isbest,istop,logid,postid,topic,author,replys,lastupdate From oblog_teampost Where teamid=" & Group_id & " And iDepth=0 And isTop=0  " & SqlPart & " Order by Lastupdate desc ) DERIVEDTBL ORDER BY istop DESC , lastupdate DESC"
怎么修改才能显示最新的500条记录(按lastupdate)

解决方案 »

  1.   


    这样会返回2000条记录吧?
    " & SqlPart & "的内容是什么?
      

  2.   

    是呀,这样多费资源,我就想要最新的500记录就可以了,SqlPart是一个where条件,
      

  3.   

    select * from
    (
    select top 500 isbest,istop,logid,postid,topic,author,replys,lastupdate 
    From oblog_teampost Where teamid=Group_id And iDepth=0 And isTop=1  Order By Lastupdate Desc
    ) DERIVEDTBL 
    ORDER BY istop DESC , lastupdate DESC
      

  4.   

    Sql="Select * from (select top 500 isbest,istop,logid,postid,topic,author,replys,lastupdate From oblog_teampost Where teamid=" & Group_id & " And iDepth=0 And isTop=1 " & SqlPart & " Order By Lastupdate Desc"
    Sql= Sql & " union "Sql= Sql & " Select top 500 isbest,istop,logid,postid,topic,author,replys,lastupdate From oblog_teampost Where teamid=" & Group_id & " And iDepth=0 And isTop=0 " & SqlPart & " Order by Lastupdate desc ) DERIVEDTBL ORDER BY istop DESC , lastupdate DESC"
      

  5.   

    你上下两部分语句怎么看起来一样啊,全靠中间那个变量来设置不同条件么
    建议你把union 改为union all,这样两个结果集组合的时候就不会合并相同的记录了以上修改之后,你的语句会选出来2000条记录 如果你要对此加以限制,可以在最外层的'select * '变成'select top 500 *'