Fix backend order query only to use distinct when needed

* This fixes most of the cases for redundant distinct usage. There may
  be more. But these are most common and most pressing on the DB size we
  have.