Table repeat count not taking complete query