Fix of SQL query