fixed an SQL query