I have a database which stores some fields as encrypted data. The reason for this is because if the database is accessed from the server then server staff cannot get a list of names and email addresses.

But the problem is that when I retrieve a list of my users from my control panel, I cannot sort them ASC or DESC on the fields that have been encrypted. Of course the data can be decrypted and displayed normally for me to read, but how to sort those columns when they are stored like...


We eventually solved this one by creating an extra column for an index using the first few letters of the subject line, so the column sorted looks like...


This way the records could be sorted in alphabetical order, and yes it can have some duplicates but at least they will be listed in the correct order of things and should one be investigated or hacked then they won't be getting any easy clues as to what is what.