Fix a small issue with SQL query