Jump to content

MySQL Sort List


xProteuSx

Recommended Posts

Say I have a column in a MySQL database, that contains the following data (each piece of data is in its own row, as stored as a string):

 

16b

166

13A

13a

4

402c

A66

A66b

 

Currently the list sorts as follows:

 

A66

A66b

13A

13a

16b

166

4

402c

 

I need it to sort as follows:

 

A66

A66b

4

13a

13A

16b

166

402c

 

So that any strings that start with a letter are first, followed by numbers in numerical order, with lower case letters coming before upper case letters.  This is a huge issue on my website, which has a database of over 35k such numbers, split up into lists.  I can't get these sorted properly.  At least it would be nice to sort as follows:

 

1

4

100

344

 

Instead of

 

1

100

344

4

 

Know what I mean?  I know that this is complicated, because the variables are strings and not numbers, but is there an easy way to do this?

Link to comment
Share on other sites

  • 2 weeks later...

Thanks cssfreakie.

 

That actually does not work.  I think that I am going to have to build a parser, because the data is a combination of numbers and letters, and is therefore treated as a string.  Somehow I have to split each string into components.  An example:

 

A13b

 

A = prefix

13 = numerical value

b = suffix

 

Then I can group entries by prefix, then by numerical value, then sort entries with the same numerical values by suffix.

 

I don't really have time to do this at the moment, but its definitely a project for the future.  Thanks for your input anyways.  The issue comes down to the entries being treated as strings, which is a necessity by definition.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.