Gibbs Posted January 29, 2007 Share Posted January 29, 2007 I have values like this in my database:VTXH001/80VTXD002/95VTXD003/95VTX > Letter of second name > Issue Number > Result. So if your name is Mr Smith and you scored 60 it would be VTXS004/60My problem is that I need to order them by the 001/002/003 (etc) part. Is it possible to search through the whole result and order it by a certain part?I hope that makes sense and thanks for any help. Link to comment https://forums.phpfreaks.com/topic/36133-solved-order-a-textnumber-string-in-mysql/ Share on other sites More sharing options...
toplay Posted January 29, 2007 Share Posted January 29, 2007 When you think that data needs to be sorted by something, it's always a good idea to have a separate column for that.Anyway, here's a quick and dirty example that should work provided you always have the Issue Number start in position 5 for a length of 3:SELECT SUBSTR(`column_name`, 5, 3) + 0 AS issue_number , tb.* FROM `table_name` tb WHERE ....some condition... ORDER BY issue_number ASC; See manual page:http://dev.mysql.com/doc/refman/5.0/en/string-functions.html Link to comment https://forums.phpfreaks.com/topic/36133-solved-order-a-textnumber-string-in-mysql/#findComment-171621 Share on other sites More sharing options...
Gibbs Posted January 29, 2007 Author Share Posted January 29, 2007 SUBSTR didn't work but it worked perfect with SUBSTRING. Thank you! Link to comment https://forums.phpfreaks.com/topic/36133-solved-order-a-textnumber-string-in-mysql/#findComment-171704 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.