Jump to content

Natural sort, letters first


silkfire

Recommended Posts

I know that if you want to make a natural sort with numbers first you just do 'ORDER BY field + 0' but what is it's the other was around and the letter prefix is of variable width?

 

Right now if I do a normal order it comes out like this:

 

EK1023

T15

T18

T2

T24

T4

T7

 

I want it like this:

 

EK1023

T2

T4

T7

T15

T18

 

What's the magic query?

Link to comment
Share on other sites

I solved it by making 2 columns and letting PHP Regex split the letter and the number part. fenway the letter part is not  of fixed width so it wouldn't work.

There is still a way to do this with locate, but two columns is better anyway.

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.