Jump to content

Sort by Alphabetical and numeric


datoshway

Recommended Posts

One way is to break into two field for sorting, like:

order by substring(cols,1,1), lpad(substring(cols,2),10,0)
                        ^ assuming only prefix single char 
                              ^ lpad like 0000000001

 

ORDER BY my_field

 

This will do the work. ORDER BY sorts numbers, strings, dates, etc in natural way.

 

ORDER BY LEFT(fld, 1), CAST(SUBSTRING(fld, 1) AS SIGNED)

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.