I have MySQL table that has an email address field, and I want to sort the table by the domain of the email address. I went looking for some complex substringy way of doing this when I came across this elegant solution: just sort by the reverse of the email address.
While this doesn’t actually sort the addresses so that, say, AOL addresses come first followed by Bellsouth, Comcast, Dartmouth, etc., it does group all the email addresses for the same domain together in order, which is all I really needed. If this is all you really need, then it’s as simple as:
select * from table order by reverse(email)