Fix distinct queries
Created by: tkcent
As of MySQL v5.7.5 they changed the default SQL mode to include ONLY_FULL_GROUP_BY.
This means that a query with fields in the ORDER BY clause also need to have those fields in the SELECT statement when they are grouped by DISTINCT.