I have seen countless instances around the web where people are using the letters of the alphabet to sort a large recordset, in fact, I have even done it before but it has been ages since that project and I had forgotten exactly how I accomplished it.
Today I working on a project where I need to sort through a large number of manufactures for a particular customer. They wanted them sortable by clicking on a the first letter of the manufacturers name.
For the English alphabet, my solution was quite simple. By using the MySQL LIKE statement and filtering out everything after 1 letter I was able to quickly and efficiently find matches for a particular letter. The example below shows a sample query assuming we are sorting by the letter A.
SELECT * FROM table_name WHERE column_name LIKE 'a%'
I also found this solution works well for numbers and other symbols. Unfortunately, in my case the client wanted all items that start with any number grouped into a single result set because there was a small number of those items. Essentially, we I needed to do a MySQL select statement that captured all items that started with any number and return those manufacturers. After doing some noodling I came up with a solution that works quite well:
SELECT * FROM table_name WHERE column_name RLIKE '^[0-9]+'
This regular expression will capture any number 0-9 and include it in the result set. This strategy could amended with different regular expression to fine tune the data selected.