Fix ordering unique records by joined table