Devesh Agrawal
Devesh Agrawal

Reputation: 9212

Order by on datetime field is not working - mysql

I want to get the date of last order placed and mobile# for all the customers. This is my query.

 SELECT c.customer_id, c.mobile, COALESCE( MAX( o.order_datetime ) ,  '0000-00-00 00:00:00' ) AS last_order_date
 FROM table_orders AS o
 RIGHT JOIN table_customers AS c ON o.customer_id = c.customer_id
 GROUP BY c.customer_id
 ORDER BY DATE( o.order_datetime ) 

It works fine. But not giving me data in asc order of o.order_datetime?

What is the error in query?

Upvotes: 2

Views: 3759

Answers (1)

Gulmuhammad Akbari
Gulmuhammad Akbari

Reputation: 2036

Try this

 ORDER BY DATE( o.order_datetime ) DESC

Upvotes: 8

Related Questions