Fix for SQL query