[ciapug] MySQL table data - "1" and "01" different values

Ryan O'Rourke ciapug@cialug.org
06 Apr 2004 10:38:04 -0500


> Ryan O'Rourke wrote:
> 
> > Is there some way to enter values such as "1" and "01" into a MySQL
> > table to have them appear as different values and still be sorted in
> > numerical order? 


On Tue, 2004-04-06 at 10:20, Lathrop Preston wrote:
> Ryan
> 
> I may be mistaken but I am afraid the answer will probably be no.
> 
> you might be able to store them as a char and use some mySQL internal 
> conversion before doing the order by.
> 
> however, as far as underlying systems are concerned
> 	01 is _not_ a numeric value and will never be represented as such with 
> the leading 0 intact.
> 
> why do you need to store the leading 0?

The numbers identify different cars. A few cars have numbers with
leading zeros, but most don't.

> If you only need leading 0 for the output, you could store integer 
> values and then do a str_pad() or similar on at output time.

I'm brand new to MySQL so I'll have to look into that.
I don't want every entry to have a leading zero, only those select few.

> Also if you do not need decimal values use INT not FLOAT

I had been using SMALLINT but it drops leading zeros as well.

Thanks for your help!