Ad
  • Custom User Avatar

    You're missing an ORDER BY id clause to comply with the requirement:
    "Two or more posts within the category can be tied by (have the same) the number of views. Use post id as a tie breaker – a post with a lower id gets a higher rank."
    Without this, ties in view count may return arbitrary posts instead of the ones with the lowest IDs.

  • Custom User Avatar

    Your current query only orders by views DESC, so if there are more than 2 posts with the same number of views, PostgreSQL will select any 2 arbitrarily, without ensuring they are the ones with the lowest ID.