move condition inside query on row callback