Fix for #85 - Invalid query when ORDER BY with DISTINCT