I have a situation where I need to sort a query by an aggregate function,
ie:

SELECT   d.ItemID, d.Title, sum(i.Quantity) AS Quantity
FROM     SomeTables
GROUP BY d.ItemID, d.Title
ORDER BY sum(i.Quantity)

However this does not work and tells me I have an "Invalid use of group
function".  So far the only way I have been able to do it is to remove the
ORDER BY completely and then do a query of this query and order by Quantity.

This seems silly and there must be a better way but much searching of the DB
docs has revealed nothing.  Anyone know how to do this?

Probably should have said earlier that the DB is MySQL (4.1.3)

--
James Smith
[EMAIL PROTECTED]
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings] [Donations and Support]

Reply via email to