Updated the SQL query