fixing select statment for both query and scan operations