Unix Technical Forum

Re: Sorting numerically within a varchar

This is a discussion on Re: Sorting numerically within a varchar within the MySQL General forum forums, part of the MySQL category; --> James, That wasn't too easy to figure out. But this will work: select * from Table1 order by substring_index(Music_Title,' ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 10:25 PM
mos
 
Posts: n/a
Default Re: Sorting numerically within a varchar

James,
That wasn't too easy to figure out. But this will work:

select * from Table1 order by
substring_index(Music_Title,' ',2), -- Extracts first 2 words
0+Substring_Index(Substring_index(Music_Title,'-',1),' ',-2), --
Extracts the number
substring_index(Music_Title,' ',-1) -- Extracts the last word
Mike



At 02:42 PM 10/3/2006, you wrote:
>If I have the following strings in a varchar column:
>
>Piano Sonata 1 - Brendel
>Piano Sonata 10 - Brendel
>Piano Sonata 11 - Brendel
>Piano Sonata 12 - Brendel
>Piano Sonata 13 - Brendel
>Piano Sonata 14 - Brendel
>Piano Sonata 15 - Brendel
>Piano Sonata 16 - Brendel
>Piano Sonata 17 - Brendel
>Piano Sonata 18 - Brendel
>Piano Sonata 19 - Brendel
>Piano Sonata 2 - Brendel
>Piano Sonata 20 - Brendel
>Piano Sonata 21 (Waldstein) - Brendel
>
>Is it possible to sort the records into the following order?
>
>Piano Sonata 1 - Brendel
>
>Piano Sonata 2 - Brendel
>Piano Sonata 10 - Brendel
>Piano Sonata 11 - Brendel
>Piano Sonata 12 - Brendel
>Piano Sonata 13 - Brendel
>Piano Sonata 14 - Brendel
>Piano Sonata 15 - Brendel
>Piano Sonata 16 - Brendel
>Piano Sonata 17 - Brendel
>Piano Sonata 18 - Brendel
>Piano Sonata 19 - Brendel
>Piano Sonata 20 - Brendel
>Piano Sonata 21 (Waldstein) - Brendel
>
>--
>MySQL General Mailing List
>For list archives: http://lists.mysql.com/mysql
>To unsubscribe: http://lists.mysql.com/mysql?unsub=mos99@fastmail.fm

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:28 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com