Fixed error in SQL query