我现在为了分页,得到两个语句,可是语句不同得到的数据确是相同的语句如下:首页:SELECT top 6 * from SYS_PRODUCT where productsubtypeId=53 or productsubtypeId=54 or productsubtypeId=0 and productId not in(select top 0  productId from SYS_PRODUCT  where productsubtypeId=53 or productsubtypeId=54 or productsubtypeId=0 order by productId)order by productId第二页:
SELECT top 6 * from SYS_PRODUCT where productsubtypeId=53 or productsubtypeId=54 or productsubtypeId=0 and productId not in(select top 6  productId from SYS_PRODUCT  where productsubtypeId=53 or productsubtypeId=54 or productsubtypeId=0 order by productId)order by productId数据库用的SqlServer,productsubtypeId和productId都是表内两个字段。我就是很纳闷为什么取出来的数据时一样的,请大家解惑,谢谢了!

解决方案 »

  1.   

    把你的数据库的前12条数据借个图上来看看呗?还有这个字段productsubtypeId是不是主键?
      

  2.   

    productSubTypeId不是主键,productId是主键,前12条数据绝对没有重复的,这个我可以保证
      

  3.   

    因为and语句就没有走 
    productsubtypeId=53 or productsubtypeId=54 or productsubtypeId=0 已经满足了条件如果你想用and 语句 应该跟没一个or语句单独使用 
      

  4.   


    你可以在这三个条件外部加一个()括号,这样就会走下面的and条件了
      

  5.   

    那请问楼上我应该怎么改?我觉得可能也是or的原因,可是由于业务需求我这些Id还必须都加上,谢谢了
      

  6.   

    SELECT top 6 * from SYS_PRODUCT where (productsubtypeId=53 or productsubtypeId=54 or productsubtypeId=0) and productId not in(select top 0 productId from SYS_PRODUCT where (productsubtypeId=53 or productsubtypeId=54 or productsubtypeId=0) order by productId)order by productId你试试行不?
      

  7.   

     where (productsubtypeId=53 or productsubtypeId=54 or productsubtypeId=0) and 
      

  8.   

    ok,搞定了,谢谢大家了,虽然搞J2EE的,但是我的SQL水平真不怎么样,谢谢大家了!!