hostfreak Posted August 2, 2006 Share Posted August 2, 2006 Thought I started another thread about this, but can't seem to find it anywhere. Anyways I have a mysql field set as an INT. It holds numbers. Then I have a page that lists the numbers in order. Well it comes up that I need that page to hold letters as well. So I changed it to a VARCHAR but then it doesn't list it right on the page (which is by the field ASC). So I am wondering how can I make the field a combination of numbers/letters and have it list in order? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 2, 2006 Share Posted August 2, 2006 Cast the field to int would be my recommendation. I haven't done it before, but it should work.[code]SELECT field FROM table ORDER BY CAST(field AS INT) ASC[/code]http://dev.mysql.com/doc/refman/5.1/en/cast-functions.htmlHere's a google result that you may want to try:http://blog.feedmarker.com/2006/02/01/how-to-do-natural-alpha-numeric-sort-in-mysql/ Quote Link to comment Share on other sites More sharing options...
hostfreak Posted August 2, 2006 Author Share Posted August 2, 2006 Neither one worked. I dont think the cast function allows for it to be casted as an INT, atleast thats what I am assuming after reading the page for it. Second one just doesn't list them right. Quote Link to comment Share on other sites More sharing options...
hostfreak Posted August 2, 2006 Author Share Posted August 2, 2006 Anyone else know of a way to do this? Quote Link to comment Share on other sites More sharing options...
AndyB Posted August 2, 2006 Share Posted August 2, 2006 SELECT whatever FROM your_table ORDER BY names + 0 ASCCan you explain what you meant by "didn't list them right". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.