Jump to content

Archived

This topic is now archived and is closed to further replies.

leeming

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

Recommended Posts

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

[quote]1
10
11
2
3
35
5[/quote]

instead of the ovious...

is there a command when selecting the field, to like

[code]"SELECT table.field AS table.field(INT) [/code]

Share this post


Link to post
Share on other sites
See the [url=http://dev.mysql.com/doc/refman/5.1/en/cast-functions.html]cast functions[/url].  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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Besides, why are you storing numbers in a varchar field?  And "+0" works wonders too, and doesn't require 4+.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.