small fix for SQL query building