select ccode from (select ROW_NUMBER() OVER(order by salescount200days desc, salescount desc) ID,ccode from products where (ccategory=247 or ccategory2=247 or ccategory3=247 or ccategory4=247 or ccategory5=247or ccategory6=247) and inactive<>1 and permalink<>'' AND (MP3_only<>1 or MP3_only is null) ) a where ID between ((1 - 1) * 20 + 1) AND (1 * 20)