Updated sql query.