If the column is an int then it will order it numerically. Other wise you have to
cast it. And dont for get the difference between ORDER BY x ASC and ORDER BY x DESC.
--Bill
DROP TABLE IF EXISTS test;
CREATE TABLE test ( i int, c char(20));
INSERT INTO test VALUES
( 1, '5' ),
( 2, '4' ),
( 3, '3' ),
( 4, '2' ),
( 5, '1' ),
( 1, '5' );
SELECT '-- Natural Order';
SELECT * FROM test;
SELECT '- ORDER by INT';
SELECT * FROM test ORDER BY i;
SELECT '- ORDER BY cast char-- ';
SELECT *, ( c + 0) AS o_col FROM test ORDER BY o_col;
Philip Montgomery wrote:
> When doing a select with an order by clause, how do you make mysql list the items in
>correct numberical order. Normally, when I run the command mysql will list 1000
>before 200 because of the initial digit. How do I correct this?
>
> Thanks,
>
> Phil
>
> Get 250 color business cards for FREE!
> http://businesscards.lycos.com/vp/fastpath/
>
> ---------------------------------------------------------------------
> 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
--
Bill Adams
TriQuint Semiconductor
---------------------------------------------------------------------
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