fix sql where nested query won't work