﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
11881	ORDER BY in aggregate subqueries is not necessary and might cause problems on some SQL servers	egenix_viktor	Anssi Kääriäinen <akaariai@…>	"Some SQL servers, like `MS SQL 2005` does not allow `ORDER BY` in subqueries without a `TOP` modifier. (It might apply to other database servers as well.) It is also suboptimal to use `ORDER BY` in the subquery of an aggregate `SELECT`, since it does not affect the result.

It might be better to just clear ordering in the subquery in this case. I suggest adding the following line in the `BaseQuery.get_aggregation` method before the `query.add_subquery(obj)` call:

{{{
obj.clear_ordering(True)
}}}

Patch against the `db\models\sql\query.py` file of the 1.1 release version has been attached."	Bug	closed	Database layer (models, ORM)	1.1	Normal	fixed	aggregate subquery order_by optimization incompatibility		Accepted	1	0	1	0	0	0
