MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 1st, 2009, 04:15 AM
sukanya.paul sukanya.paul is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2008
Posts: 11 sukanya.paul User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 53 sec
Reputation Power: 0
Arranging mysql data

hi i have a table which has a field called month whose values are
January,February,March etc in no particular order

i am selecting all daya from this table and the month values are in the following order:
January
November
December
February
March
April
May
June
July
August
September
October

i want it to be displayed in the proper order
January
February
March
..
..
..
December

Can some1 please help me with this.
Thanks in advance
Suk

Reply With Quote
  #2  
Old July 1st, 2009, 05:19 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,687 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 9 h 27 m 54 sec
Reputation Power: 2458
Code:
ORDER 
    BY POSITION( LEFT(monthname,3) 
          IN 'JanFebMarAprMayJunJulAugSepOctNovDec' )
Comments on this post
srisa agrees: Take a bow monsieur
cafelatte agrees: Happy Canada Day!
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book

Reply With Quote
  #3  
Old July 2nd, 2009, 09:18 AM
cafelatte cafelatte is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Mar 2008
Posts: 753 cafelatte User rank is First Lieutenant (10000 - 20000 Reputation Level)cafelatte User rank is First Lieutenant (10000 - 20000 Reputation Level)cafelatte User rank is First Lieutenant (10000 - 20000 Reputation Level)cafelatte User rank is First Lieutenant (10000 - 20000 Reputation Level)cafelatte User rank is First Lieutenant (10000 - 20000 Reputation Level)cafelatte User rank is First Lieutenant (10000 - 20000 Reputation Level)cafelatte User rank is First Lieutenant (10000 - 20000 Reputation Level)cafelatte User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 2 Weeks 21 h 30 m 37 sec
Reputation Power: 107
You could also do something like this:
Code:
SELECT monthname 
  FROM monthnames 
 ORDER 
      BY STR_TO_DATE(monthname,'%M');

Reply With Quote
  #4  
Old July 2nd, 2009, 09:50 AM
r937's Avatar
r937 r937 is offline
SQL Consultant
Click here for more information.
 
Join Date: Feb 2003
Location: Toronto Canada
Posts: 20,687 r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level)r937 User rank is General 22nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Months 1 Week 3 Days 9 h 27 m 54 sec
Reputation Power: 2458
Quote:
Originally Posted by cafelatte
STR_TO_DATE(monthname,'%M');
that works, but it's a pretty bad hack
Code:
SELECT monthname 
     , STR_TO_DATE(monthname,'%M') as m
  FROM monthnames 
;
monthname  m
January    0000-01-00
November   0000-11-00
December   0000-12-00
February   0000-02-00
March      0000-03-00
April      0000-04-00
May        0000-05-00
June       0000-06-00
July       0000-07-00
August     0000-08-00
September  0000-09-00
October    0000-10-00
those "dates" are abysmally bad


Reply With Quote
  #5  
Old July 2nd, 2009, 02:21 PM
fubes2000's Avatar
fubes2000 fubes2000 is offline
manwich
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Location: Canadanistan
Posts: 372 fubes2000 User rank is Captain (20000 - 30000 Reputation Level)fubes2000 User rank is Captain (20000 - 30000 Reputation Level)fubes2000 User rank is Captain (20000 - 30000 Reputation Level)fubes2000 User rank is Captain (20000 - 30000 Reputation Level)fubes2000 User rank is Captain (20000 - 30000 Reputation Level)fubes2000 User rank is Captain (20000 - 30000 Reputation Level)fubes2000 User rank is Captain (20000 - 30000 Reputation Level)fubes2000 User rank is Captain (20000 - 30000 Reputation Level)fubes2000 User rank is Captain (20000 - 30000 Reputation Level)  Folding Points: 154682 Folding Title: Super Ultimate Folder - Level 1Folding Points: 154682 Folding Title: Super Ultimate Folder - Level 1Folding Points: 154682 Folding Title: Super Ultimate Folder - Level 1Folding Points: 154682 Folding Title: Super Ultimate Folder - Level 1Folding Points: 154682 Folding Title: Super Ultimate Folder - Level 1Folding Points: 154682 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 4 Days 8 h 22 m 38 sec
Reputation Power: 236
The ideal situation would be to store the month as an INT and do the translation to long name during the query or application execution. If it is part of a multiple-field storage of date information it would be best to simply consolidate to a single DATE type and extract the relevant data with the appropriate functions.
__________________

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > Arranging mysql data


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
Stay green...Green IT