Fixed incorrect SQL query