MYSQL sorting problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
number
Forum Newbie
Posts: 3
Joined: Thu Apr 27, 2006 11:44 am

MYSQL sorting problem

Post by number »

Hey,
I'm trying to sort a table( which contains order details eg productname/quantity/customers details) by the Sum of the quantities for each particular product.
Basically, I'm trying to output the three most popular products which have been ordered.

I'm trying to use:

Code: Select all

$query1 = "SELECT DISTINCT productName FROM shoeplanetorders ORDER BY SUM(quantity) DESC";
         $result1=mysql_query($query1);
which the MYSQL query browser says is "Invalid use of Group function".


I'm wondering if anyone can help me to return the most popular products, by the total sum of the quanties purchased? By leaving out the "SUM()" around the ORDER BY quantitity statement, it simply returns the products by the order of decreasing size of an individual order. Thanks in advance.
User avatar
hawleyjr
BeerMod
Posts: 2170
Joined: Tue Jan 13, 2004 4:58 pm
Location: Jax FL & Spokane WA USA

Post by hawleyjr »

Don't Double Post!

Locked.

viewtopic.php?p=267093
Locked