MYSQL order by regexp

written by justin on September 14th, 2009 @ 02:32 PM

So, today I found that you can use regular expressions in the order by clause in MySQL. I'm using this for a field that can be either number, alpha, or a mix.
This is what is looks like. I'm saying that if the number starts with 0 - 9 then add 0 and it sorts like a number, otherwise, just sort on the alpha.


'if(number REGEXP \'^[0-9]\',number + 0, number)'

Post a comment