Fixed invalid SQL query