Fix syntax error in query