Mysql Query - Order By Not Working

Posted by jwzk on Stack Overflow See other posts from Stack Overflow or by jwzk
Published on 2010-04-18T13:04:09Z Indexed on 2010/04/18 13:13 UTC
Read the original article Hit count: 179

Filed under:
|
|

I'm running Mysql 5.0.77 and I'm pretty sure this query should work?

SELECT * FROM purchases WHERE time_purchased BETWEEN '2010-04-15 00:00:00' AND '2010-04-18 23:59:59' ORDER BY time_purchased ASC, order_total DESC

time_purchased is DATETIME, and an index.

order_total is DECIMAL(10,2), and not an index.

I want to order all purchases by the date (least to greatest), and then by the order total (greatest to least).

So I would output similar to:

2010-04-15 $100

2010-04-15 $80

2010-04-15 $20

2010-04-16 $170

2010-04-16 $45

2010-04-16 $15

2010-04-17 $274

.. and so on.

The output I am getting from that query has the dates in order correctly, but it doesn't appear to sort the order total column at all. Thoughts?

Thanks.

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql