Jump to content


ORDER BY: order varchar (interger data, 0 fields) like int...

  • Please log in to reply
3 replies to this topic

#1 leeming

  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 06 July 2006 - 04:32 PM

ok in my databse field, 0 is an option. and since int doesnt save 0, and have to use varchar instead...

this is my problem...

im wanting to order the table by this field, but some thing like the following outputs


instead of the ovious...

is there a command when selecting the field, to like

"SELECT table.field AS table.field(INT)

Im not perfect ;) lol

#2 Wildbug

  • Members
  • PipPipPip
  • Advanced Member
  • 1,149 posts

Posted 06 July 2006 - 04:42 PM

See the cast functions.  I haven't tried it, but something like "SELECT CAST(table.field AS UNSIGNED) AS IntColumn ... ORDER BY IntColumn" might work.

And what do you mean by "int doesnt save 0"?  You can have a zero in an integer column.  If you need to differentiate between "no value" and "zero," use NULL.
Twice a day my clock works PERFECTLY!  I can't figure out what's wrong with it.

#3 leeming

  • Members
  • PipPipPip
  • Advanced Member
  • 93 posts

Posted 06 July 2006 - 04:45 PM

ok thanks, i did come across the CAST function slightly after i posted this... but i just didnt understand it...

as for the '0' in INT, i didnt know that.. always been told to us it as varchar
Im not perfect ;) lol

#4 fenway

  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 06 July 2006 - 05:01 PM

Besides, why are you storing numbers in a varchar field?  And "+0" works wonders too, and doesn't require 4+.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users