Additional fix for SQL query