Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'imx365.album_images.upload_datetime' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by SELECT DATE_FORMAT(upload_datetime, '%Y') AS year FROM album_images WHERE userid = 135080 GROUP BY DATE_FORMAT(upload_datetime, '%Y') HAVING COUNT(*) >= 1 ORDER BY upload_datetime DESC