i want to order an item by the number in the database field 1,2,3,4,5,6 iup to 15 but it is displaying 1,10,11 and up which i dont want
ORDER BY beau_products.order ASC
the order column is varchar (10)
ORDER BY NUMBER 1,10,11 incorrect
Moderator: General Moderators
-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: ORDER BY NUMBER 1,10,11 incorrect
It's using string ordering because you're storing numbers as strings. Don't do that. Use INT, SMALLINT, TINYINT, etc. Use the right column type for your data.
Re: ORDER BY NUMBER 1,10,11 incorrect
In the interim you can use CAST, but you really want to correct this.
Code: Select all
SELECT foo FROM table_name ORDER BY CAST(`order` AS UNSIGNED) ASC-
jonnyfortis
- Forum Contributor
- Posts: 462
- Joined: Tue Jan 10, 2012 6:05 am
Re: ORDER BY NUMBER 1,10,11 incorrect
thanks. i will change the column to int, thanks againCelauran wrote:In the interim you can use CAST, but you really want to correct this.
Code: Select all
SELECT foo FROM table_name ORDER BY CAST(`order` AS UNSIGNED) ASC