Sorting a varchar field...

2002-05-17 Thread Maksim Rogov

Hi, I am new to the list :)

Have a question, I have not been able to find any information on this on the
MySQL site.

Is it possible to sort a varchar field that contains numbers as an integer
field?

ie. right now it is sorting 1,2,4,10,11,12 as:

1
10
11
2
4

I would like to see it properly sorted. The reason the field is varchar is
because we may *sometimes* have string characters in the field.

Thanks for your help,

Maksim


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




RE: Sorting a varchar field...

2002-05-17 Thread Gurhan Ozen


SELECT ... FROM tablename ORDER BY varcharcolumn+0;


Gurhan

-Original Message-
From: Maksim Rogov [mailto:[EMAIL PROTECTED]]
Sent: Friday, May 17, 2002 9:44 AM
To: [EMAIL PROTECTED]
Subject: Sorting a varchar field...


Hi, I am new to the list :)

Have a question, I have not been able to find any information on this on the
MySQL site.

Is it possible to sort a varchar field that contains numbers as an integer
field?

ie. right now it is sorting 1,2,4,10,11,12 as:

1
10
11
2
4

I would like to see it properly sorted. The reason the field is varchar is
because we may *sometimes* have string characters in the field.

Thanks for your help,

Maksim


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail
[EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




sorting the varchar field?

2002-02-05 Thread Vishakha Mali_Wagh


hi again,

Now I need to sort a field of varchar type.  But the filed values are like...

b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12
meaning thereby, an integer prefixed by some character.

Is there any straight  way to frame the query?
thanx in advance for your time,
regards,
-vishi 


-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php




Re: sorting the varchar field?

2002-02-05 Thread Diana Soares

On Tue, 2002-02-05 at 10:18, Vishakha Mali_Wagh wrote:
 Now I need to sort a field of varchar type.  But the filed values are like...
 b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12
 meaning thereby, an integer prefixed by some character.
 Is there any straight  way to frame the query?

OK, if the prefix is always one character you could use:

SELECT ... FROM ... 
ORDER BY left(field,1), SUBSTRING(field,2)/XX

where XX is the upper limit of the integer part of the field.
I'm shure there are much better ways to do this, because this only
applies when your field has a prefix of only one character and when you
know the upper limit of the integer part of the field.

Note that if you are using MySQL 4.0.2, you don't need this because you
have the CAST() and CONVERT() functions.


-- 
Diana Soares

(sql)

-
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/   (the list archive)

To request this thread, e-mail [EMAIL PROTECTED]
To unsubscribe, e-mail [EMAIL PROTECTED]
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php