You can use FIELD in the ORDER BY. See pp. 330 of the
MySQL Cookbook, or FIELD in the MySQL docs:

http://dev.mysql.com/doc/mysql/en/string-functions.html

mysql> SELECT * FROM test;
+------+-------+
| name | month |
+------+-------+
| foo  | Mar   |
| bar  | Jan   |
| baz  | May   |
| quux | Nov   |
| qaax | Apr   |
| qiix | Dec   |
+------+-------+
6 rows in set (0.00 sec)

mysql> SELECT * FROM test
-> ORDER BY FIELD(month, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');
+------+-------+
| name | month |
+------+-------+
| bar | Jan |
| foo | Mar |
| qaax | Apr |
| baz | May |
| quux | Nov |
| qiix | Dec |
+------+-------+
6 rows in set (0.00 sec)


____________________________________________________________
Eamon Daly



----- Original Message ----- From: "N. Kavithashree" <[EMAIL PROTECTED]>
To: <mysql@lists.mysql.com>
Sent: Tuesday, January 25, 2005 1:19 AM
Subject: orderbymonths




hello,

is there any way so that months r ordered as that of calender year.

means . i have a month field of 3 chars. like Jan, Feb, Mar etc

when i select distinct months , the result will be displayed in the
calender year month order.

but if i use order by mon then this order jan,feb,mar will go and it will
order accorg to the first char of the month name.

but i want to arrnage in calender month order even when i count the stocks
for each month with group by statement.

is there any option to sort with 2nd and 3rd char also like that of sql in
mysql ?

--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]




--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to