[aklug] Re: MySQL sorting alphanumerics

From: Shane Spencer <shane@bogomip.com>
Date: Sat Apr 03 2010 - 09:30:22 AKDT

I keep forgetting that there is a specific way to do things and a
generic way to do things. Generic would be using a natural sort which
takes a lot into account. Specific would be knowing your limits and
working directly within them. So I thunk to myself - Shane - what is
the super specific way to do this assuming there are only 1-99 ports
in a switch and Null-A-Z modules.

The subselect is for show.. stating it can deal with random sorting.
I'm not sure if using three substrings is less evil than the natural
sort function. But it's specific :)

mysql> select a from (select a from xyz order by RAND()) as abc order
by substring(a,1,1), substring(a,3,1), substring(a,2,1);
+------+
| a |
+------+
| 1 |
| 10 |
| 2 |
| 3 |
| 4 |
| 42 |
| 9 |
| A3 |
| A9 |
| A10 |
| C7 |
| D3 |
+------+
12 rows in set (0.00 sec)
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Sat Apr 3 09:30:33 2010

This archive was generated by hypermail 2.1.8 : Sat Apr 03 2010 - 09:30:33 AKDT