Updated the query as per the review comments