Tag Archives: MySQL OrderBy Error

MySQL OrderBy Error: Expression #1 of ORDER BY

Add any_value () package to all non-aggregated columns (that is, data directly fetched in the table)

**Note: The columns used in order by should also be wrapped**

The ANY_VALUE() function is useful when the ONLY_FULL_GROUP_BY mode is enabled and GROUP BY is used for query; this function is used to suppress the value rejection caused when the ONLY_FULL_GROUP_BY mode is enabled;
example:

SELECT
	any_value ( a.id ) AS id,
	a.footprint_id AS footprintId,
	any_value ( a.footprint_type ) AS footprintType,
	any_value ( a.user_id ) AS userId 
FROM
	info_footprint a 
WHERE
	a.footprint_type = 3 
	AND a.user_id = 1 
	AND a.del_flag = '0' 
GROUP BY
	footprint_id 
ORDER BY
	any_value(a.id) DESC 
	LIMIT 10;