Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 07-26-2006, 02:42 AM   PM User | #1
bphein1980
Regular Coder

 
Join Date: Feb 2005
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
bphein1980 is an unknown quantity at this point
Beginner Order By question....

I have a column in a table that is for weight classes (like in wrestling) that goes something like....

67.5
75
82.5
100
110
125
140
140+

My problem is that I cannot store them as INT (or a number) because of the plus sign for the last weight class. So, when I have them ordered (ORDER BY weight ASC) it sorts them wrong.... sorts everything by the first number (like alpha if it was sorting text because it is stored as VARCHAR).

How can I get around this? I have to have the plus sign in the last record and INT or FLOAT will not accept the plus sign. Like I said, I'm a beginner, so I'm sure I am missing something very simple.

Thanks for helping me out.
bphein1980 is offline   Reply With Quote
Old 07-26-2006, 02:49 AM   PM User | #2
Kid Charming
Regular Coder

 
Join Date: Jun 2005
Posts: 804
Thanks: 0
Thanked 0 Times in 0 Posts
Kid Charming is an unknown quantity at this point
Try

ORDER BY yourcolumn+0
Kid Charming is offline   Reply With Quote
Old 07-26-2006, 02:53 AM   PM User | #3
bphein1980
Regular Coder

 
Join Date: Feb 2005
Posts: 136
Thanks: 0
Thanked 0 Times in 0 Posts
bphein1980 is an unknown quantity at this point
Thank you for the reply, I changed my code but it did not effect how they were ordered.

Im still searching Google, but I just cant seem to find the answer.

NEVERMIND - I put the "+0" in the wrong spot. Oopsie! Thank you very much for the help. Consider this problem a closed case.

Thanks for the quick help
bphein1980 is offline   Reply With Quote
Old 07-26-2006, 03:02 AM   PM User | #4
Kid Charming
Regular Coder

 
Join Date: Jun 2005
Posts: 804
Thanks: 0
Thanked 0 Times in 0 Posts
Kid Charming is an unknown quantity at this point
Forget my first post and try this:

Code:
ORDER BY
 CASE yourcolumn
  WHEN '140+' THEN 1
  ELSE 0
 END
,yourcolumn
or

Code:
ORDER BY
 FIELD(yourcolumn,'140+')
,yourcolumn
They're both equivalent.
Kid Charming is offline   Reply With Quote
Old 07-26-2006, 04:42 AM   PM User | #5
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
The small difference being the latter will only run on mysql, whereas the first is standard sql and will run across any db.
guelphdad is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:50 PM.


Advertisement
Log in to turn off these ads.